CPlusOOP
SiteMap
OO Analysis
Problem Analysis
User Defined Types
«Prev
Next»
OO-Design
Detailed Design
OO Programming
Procedural Programming
Object Oriented Approach
Design Process
Eliminate Classes Problem Domain
OO Design Conclusion
Object Oriented Concepts
Responsibilities Collaborators
Video Store Example
OOA Benefits Encapsulation
Structured Programming
Benefits OOA
OO Conclusion
Object Oriented Approach
OOA Simpler Analysis
OOA Enables Reuse
Simplifies Team Work
OOP Conclusion
User Defined Data Types
Classes Objects
Class Data Type
Choosing Class Attributes
Object Instance
Class Object Difference
Class Composition
When to use Composition
Build Complex Objects
Drawing Class Diagram
Class Construction Conclusion
When To Use Composition - Exercise
Use composition in the course project
Objective:
Build a more robust Check class.
Scoring
This exercise is not scored. It's an opportunity for you to check your understanding of the material covered in the preceding lesson. When you are finished, click the
Submit
button to view the suggested results.
Background/overview
The
Check
class has a number of separate attributes that should really be encapsulated into classes of their own, because they have business rules. (For example, the
cents
attribute cannot be over
99
, and the
month
attribute cannot be over
12
.) These business rules are likely to be used elsewhere, too (think about the balance attribute of the
CheckingAccount
class, for example).
Instructions
Define a
Money
class that has integer attributes for dollars and cents.
Then define a
Date
class with integer attributes for days, years, and months.
Use these two new classes and composition to create a better definition for a
Check
class. Finally, draw a class diagram that shows how all three classes are related.