-
February 28th, 2014, 03:22 PM
#16
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 03:25 PM.
-
March 1st, 2014, 12:46 AM
#17
Re: Homework help: is this a good design?
Originally Posted by TSLexi
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 01:04 AM.
-
March 1st, 2014, 12:30 PM
#18
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.
-
March 4th, 2014, 07:59 AM
#19
Re: Homework help: is this a good design?
Originally Posted by TSLexi
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
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
|