| < Day Day Up > |
Conclusion
This chapter covers the design process for complete systems. It focuses on combining several classes to build a system. This system is represented by UML class diagrams. The example in this chapter shows the first pass at creating a design and is not
Implementing Some Blackjack Code I recently came across a complete implementation of a blackjack game in the book Java 1.1 Developers Guide by Jamie Jaworski. If you would like to actually get your hands dirty and write some code to implement another blackjack design, you might want to pick up this good, compressive Java book.
In the
|
| < Day Day Up > |
| < Day Day Up > |
ReferencesGilbert, Stephen, and Bill McCarty. Object-Oriented Design in Java . The Waite Group, 1998. Jaworski, Jamie. Java 1.1 Developers Guide . Sams Publishing, 1997. Wrifs-Brock, R., B. Wilkerson, and L. Weiner. Designing Object-Oriented Software . Prentice-Hall, 1990. Ambler, Scott. The Object Primer . Cambridge University Press, 1998. Weisfeld, Matt and John Ciccozzi. "Software by Committee," Project Management Journal , volume 5, number 1. Pages 30 “36, September, 1999. |
| < Day Day Up > |
| < Day Day Up > |
Chapter 7. Mastering Inheritance and CompositionInheritance and composition play major roles in the design of object-oriented (OO) systems. In fact, many of the most difficult and interesting design decisions come down to deciding between inheritance and composition.
Both inheritance and composition are mechanisms for reuse.
Inheritance
, as its
Composition
involves using other classes to build more complex classes. There is no parent/child relationship in this case. Basically, complex objects are
A Real-World Example It might be helpful to explain the differences between is-a and has-a relationships based on terms from the relational database world. Is-a represents a hierarchical relationship between entity types (tables), whereas has-a represents a referential relationship.
When OO technologies first entered the mainstream, inheritance was all the rage. The fact that you could design a class once and then inherit functionality from it was
However, over the past several
The good news is that the discussions about whether to use inheritance or composition are a natural progression toward some seasoned middle ground. As in all philosophical debates, there are fanatical people on both sides of the argument. Fortunately, as is normally the case, these heated discussions have led to a more
For reasons that we will discuss later in this chapter, some people believe that inheritance should be avoided and composition should be the design method of choice. The argument is
The fact that inheritance is often misused and
The bottom line is that inheritance and composition are both important techniques in building OO systems. Designers and developers simply need to take the time to understand the strengths and weaknesses of both and to use each in the proper contexts. |
| < Day Day Up > |