|
-
February 8th, 2005, 04:11 AM
#1
Which is better option
I have two classes PersonalDetails and ProfessionalDetails. Now I have to derive classes for permanent / Temp / consultant employee from PersonalDetails. The derived class should also contain information of ProfessionalDetails.
So I have some options
1. Derive the classes taking both as base
2. Derive the classes from PersonalDetails and add object of ProfessionalDetails.
I would like to know which is better in terms of coding, memory usage etc.
Thanks
bashish
-
February 8th, 2005, 04:37 AM
#2
Re: Which is better option
3. Have both as member objects.
The relationship between an "employee" and these details is HAS-A in both cases, not IS-A
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
February 8th, 2005, 06:14 AM
#3
Re: Which is better option
3. Have both as member objects.
What about a Decorator? I think it's appropriate because only some people need Professional Details. And if later he finds out that some people need some ExtraDetails, then the changes needed are minimal.
-
February 8th, 2005, 07:43 AM
#4
Re: Which is better option
A good point, it's just that I read the question as implying that all the employees would have both types of details, so that level of flexibility might be classed as over-design in this case. Decorator is certainly worth considering if there was a possibility that professional details might not be applicable, though.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
February 8th, 2005, 08:17 AM
#5
Re: Which is better option
Can you give me details of Decorator
bashish
-
February 8th, 2005, 08:37 AM
#6
Re: Which is better option
-
February 8th, 2005, 10:54 AM
#7
Re: Which is better option
Not to mention "Design Patterns" by Gamma & Co (Gang of Four) and "Thinking in Patters" in Java or C++ by Bruce Eckel.
-
February 9th, 2005, 01:09 AM
#8
Re: Which is better option
Thanks every one.
bashish
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|