Q
qazmlp
What do you recommend among the following two designs, considering
all the standard design aspects ?
1)
class base
{
public:
virtual ~base() { }
virtual long int getId() = 0;
private:
static const long int BASE_ID = 10000 ;
};
long int base::getId()
{
return BASE_ID ;
}
class derived11 : public base
{
public:
virtual ~derived11()
{
}
virtual long int getId()
{
return base::getId() + ID ;
}
private:
static const long int ID = 11 ;
};
class derived12 : public base
{
public:
virtual ~derived12()
{
}
virtual long int getId()
{
return base::getId() + ID ;
}
private:
static const long int ID = 12 ;
};
2)
class base
{
public:
virtual long int getId() = 0;
protected:
static const long int BASE_ID = 10000 ;
};
class derived11 : public base
{
public:
virtual long int getId()
{
return BASE_ID + ID ;
}
private:
static const long int ID = 11 ;
};
class derived12 : public base
{
public:
virtual long int getId()
{
return BASE_ID + ID ;
}
private:
static const long int ID = 12 ;
};
all the standard design aspects ?
1)
class base
{
public:
virtual ~base() { }
virtual long int getId() = 0;
private:
static const long int BASE_ID = 10000 ;
};
long int base::getId()
{
return BASE_ID ;
}
class derived11 : public base
{
public:
virtual ~derived11()
{
}
virtual long int getId()
{
return base::getId() + ID ;
}
private:
static const long int ID = 11 ;
};
class derived12 : public base
{
public:
virtual ~derived12()
{
}
virtual long int getId()
{
return base::getId() + ID ;
}
private:
static const long int ID = 12 ;
};
2)
class base
{
public:
virtual long int getId() = 0;
protected:
static const long int BASE_ID = 10000 ;
};
class derived11 : public base
{
public:
virtual long int getId()
{
return BASE_ID + ID ;
}
private:
static const long int ID = 11 ;
};
class derived12 : public base
{
public:
virtual long int getId()
{
return BASE_ID + ID ;
}
private:
static const long int ID = 12 ;
};