The first is complicated and slow. The second is simple and fast. I
don't see any benefit to the polymorphism used in the first.
qazmlp1209@rediffmail.com (qazmlp) might (or might not) have written
this on (or about) 31 Jan 2004 03:36:15 -0800, :
[color=blue]
>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 ;
>};[/color]
Robert C. Martin | "Uncle Bob"
Object Mentor Inc. | unclebob @ objectmentor . com
501 N. Riverside Dr.| Tel: (800) 338-6716
Suite 206 | Fax: (847) 775-8174 |
www.objectmentor.com
| |
www.XProgramming.com
Gurnee, IL, | Training and Mentoring |
www.junit.org
60031 | OO, XP, Agile, C++, Java, C# |
http://fitnesse.org