CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2004
    Posts
    137

    Exclamation 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

  2. #2
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    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


  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    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


  5. #5
    Join Date
    Mar 2004
    Posts
    137

    Re: Which is better option

    Can you give me details of Decorator

    bashish

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Which is better option


  7. #7
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  8. #8
    Join Date
    Mar 2004
    Posts
    137

    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
  •  





Click Here to Expand Forum to Full Width

Featured