Homework help: is this a good design? - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: Homework help: is this a good design?

  1. #16
    Join Date
    Dec 2013
    Posts
    75

    Re: Homework help: is this a good design?

    Well, the instructor required us to write getter and setter methods for Employee's data members.

    Also, as of yet, we have no idea if the implementation of Employee will significantly change in its derived classes, and our compiler can devirtualize method calls.
    Last edited by TSLexi; February 28th, 2014 at 02:25 PM.

  2. #17
    Join Date
    Jul 2013
    Posts
    258

    Re: Homework help: is this a good design?

    Quote Originally Posted by TSLexi View Post
    Well, the instructor required us to write getter and setter methods for Employee's data members.

    Also, as of yet, we have no idea if the implementation of Employee will significantly change in its derived classes, and our compiler can devirtualize method calls.
    Well, regarding my comment on getter/setters. They're fine because they provide a certain level of encapsulation. So if a class has properties, expose them using getters/setters. It's just that by returning the getter by reference you nullified their purpose as I explained. But you've changed that now so it's fine.

    Regarding my suggestion to remove everything virtual. This is a design issue, not a performance issue. You have implemented Employee as a value object and value objects shouldn't be inherited from. If the methods are left virtual you suggest the opposite. Someone may use the Employee as a base class and inherit from it. That's a bad idea so simply remove that possibility by making all methods non-virtual.

    If Employee later is to be used as an OO polymorphic class then the current implementation must be changed. Employee should be made an abstract, preferably pure, interface; Everything should be virtual, it should have no state, and copying and construction should be disabled.

    Both value classes and OO polymorphic classes can be part of an OO design but they serve very different purposes. Be clear what kind of class you're writing! (C++ Coding Standards by Sutter & Alexandrescu, item 32).
    Last edited by razzle; March 1st, 2014 at 12:04 AM.

  3. #18
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,251

    Re: Homework help: is this a good design?

    As Razzle suggests, sometimes coding for 'what might happen' in the future isn't a good idea.
    Many times it is better to code for what you have now than coding for a lot of flexibility in the future. To often the future features never come or come in such a way that the built-in flexibility still doesn't allow for them. That leaves you with a too abstracted design that is difficult to understand and maintain.

  4. #19
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,012

    Re: Homework help: is this a good design?

    Quote Originally Posted by TSLexi View Post
    Employee.hpp
    Code:
    //inclusion guards
    #ifndef EMPLOYEE_HPP
    #define EMPLOYEE_HPP
    
    //including string header file
    #include <string>
    using std::string;
    Never put a using declaration at global scope in a header file. Every file that includes this header will get that using declaration, which can cause name conflicts.
    IMO, it's way easier to learn to type std:: quickly than to put using declarations all over the place.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center