Click here to Skip to main content
15,890,399 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionData Encapsulation Pin
pix_programmer8-Jun-12 21:12
pix_programmer8-Jun-12 21:12 
AnswerRe: Data Encapsulation Pin
Richard MacCutchan8-Jun-12 22:07
mveRichard MacCutchan8-Jun-12 22:07 
AnswerRe: Data Encapsulation Pin
Aescleal9-Jun-12 9:40
Aescleal9-Jun-12 9:40 
QuestionMy assignment aggregation, composition and inheritance Pin
David96378-Jun-12 19:23
David96378-Jun-12 19:23 
AnswerRe: My assignment aggregation, composition and inheritance Pin
Richard MacCutchan8-Jun-12 22:02
mveRichard MacCutchan8-Jun-12 22:02 
GeneralRe: My assignment aggregation, composition and inheritance Pin
David96379-Jun-12 0:13
David96379-Jun-12 0:13 
GeneralRe: My assignment aggregation, composition and inheritance Pin
Richard MacCutchan9-Jun-12 0:20
mveRichard MacCutchan9-Jun-12 0:20 
AnswerRe: My assignment aggregation, composition and inheritance Pin
Aescleal9-Jun-12 10:09
Aescleal9-Jun-12 10:09 
Inheritance is a "is a" relationship between two objects. If A is a subtype of B then "A is a B". Every behaviour of objects of class B is exhibited by objects of class A (this is called the Liskov Substitution principle). In your model all ShiftSupervisors are also Employees so derive ShiftSupervisor from Employee.

Composition is a "has a" relationship between two objects. If A is composed of B then every instance of A has an instance of B with the same lifetime associated with it. By same lifetime I mean an object of class B springs into life every time an object of class A is created and the object of class B is destroyed when the object of class A is destroyed. In your example and Employee has a name so give each object of class Employee a data member of class.

Aggregation is a more general form of composition. It's essentially the same (a "has relationship") but with a different lifetime. In your example more than one Employee can share the same address so when an Employee object is destroyed the address they live at is not necessarily wiped off the map. Give each Employee object a reference to, pointer to or a shared pointer (preferably) an object of class Address.

And while I'm on the subject your Name and Address classes are an okay representation of their UML. There are way too many get/set member functions on each of them (how many houses are going to change their state, city of country?). And women don't "set their surnames" when they get married, they change_surname_to instead. And you really don't need default constructors on them either, even if want to use the type in a collection class.

You want to define Employee next and when you've done that ShiftSupervisor. Have a crack at both and if you're having trouble we can look at the definitions and perhaps drop a few hints as to how to proceed.

modified 9-Jun-12 16:22pm.

QuestionBuild error with Visual C++ 2010 Pin
Falconapollo8-Jun-12 17:10
Falconapollo8-Jun-12 17:10 
AnswerRe: Build error with Visual C++ 2010 Pin
Richard MacCutchan8-Jun-12 22:53
mveRichard MacCutchan8-Jun-12 22:53 
GeneralRe: Build error with Visual C++ 2010 Pin
Falconapollo8-Jun-12 23:05
Falconapollo8-Jun-12 23:05 
GeneralRe: Build error with Visual C++ 2010 Pin
Richard MacCutchan8-Jun-12 23:29
mveRichard MacCutchan8-Jun-12 23:29 
GeneralRe: Build error with Visual C++ 2010 Pin
Falconapollo8-Jun-12 23:35
Falconapollo8-Jun-12 23:35 
AnswerRe: Build error with Visual C++ 2010 Pin
Stephen Hewitt10-Jun-12 1:17
Stephen Hewitt10-Jun-12 1:17 
QuestionIf CDialog is destroyed is UI CWinThread created While object was alive get destroyed as Well Pin
ForNow8-Jun-12 2:31
ForNow8-Jun-12 2:31 
AnswerRe: If CDialog is destroyed is UI CWinThread created While object was alive get destroyed as Well Pin
«_Superman_»8-Jun-12 2:46
professional«_Superman_»8-Jun-12 2:46 
GeneralRe: If CDialog is destroyed is UI CWinThread created While object was alive get destroyed as Well Pin
ForNow8-Jun-12 10:52
ForNow8-Jun-12 10:52 
GeneralRe: If CDialog is destroyed is UI CWinThread created While object was alive get destroyed as Well Pin
«_Superman_»8-Jun-12 16:11
professional«_Superman_»8-Jun-12 16:11 
AnswerRe: If CDialog is destroyed is UI CWinThread created While object was alive get destroyed as Well Pin
Albert Holguin8-Jun-12 4:33
professionalAlbert Holguin8-Jun-12 4:33 
QuestionCorruption of the heap. Why ? Pin
sdancer757-Jun-12 23:49
sdancer757-Jun-12 23:49 
AnswerRe: Corruption of the heap. Why ? Pin
Rolf Kristensen8-Jun-12 2:01
Rolf Kristensen8-Jun-12 2:01 
GeneralRe: Corruption of the heap. Why ? Pin
Erudite_Eric8-Jun-12 2:35
Erudite_Eric8-Jun-12 2:35 
GeneralRe: Corruption of the heap. Why ? Pin
sdancer758-Jun-12 6:02
sdancer758-Jun-12 6:02 
AnswerRe: Corruption of the heap. Why ? Pin
Aescleal8-Jun-12 3:00
Aescleal8-Jun-12 3:00 
GeneralRe: Corruption of the heap. Why ? Pin
sdancer758-Jun-12 6:03
sdancer758-Jun-12 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.