| < Day Day Up > |
Composition
It is natural to think of objects as containing other objects. A television set contains a tuner and video display. A computer contains video cards, keyboards, and drives. Although the computer can be considered an object unto itself, the drive is also considered a valid object. In fact, you could
In this way, objects are often built, or
Has-a RelationshipsAlthough an inheritance relationship is considered an is-a relationship for reasons already discussed, a composition relationship is termed a has-a relationship. Using the example in the previous section, a television has-a tuner and has-a video display. A television is obviously not a tuner, so there is no inheritance relationship. In the same vein, a computer has-a video card, has-a keyboard, and has-a disk drive. The topics of inheritance, composition, and how they relate to each other is covered in great detail in Chapter 7, "Mastering Inheritance and Composition." |
| < Day Day Up > |
| < Day Day Up > |
ConclusionThere is a lot to cover when discussing OO technologies. However, you should leave this chapter with a good understanding of the following topics:
This chapter covers the fundamental OO concepts. By now you should have a good grasp of what OO concepts are all about. |
| < Day Day Up > |
| < Day Day Up > |
Chapter 2. How to Think in Terms of ObjectsIn Chapter 1, "Introduction to Object-Oriented Concepts," you learned the fundamental object-oriented (OO) concepts. The rest of the book digs more deeply into these concepts. Many factors go into a good design, whether it is an OO design or not. The fundamental unit of OO design is the class. The desired end result of OO design is a robust and functional object model ”a system. As with most things in life, there is no single right or wrong way to approach a problem. There are usually many different ways to tackle the same problem. So, when attempting to design an OO solution, don't get hung up in trying to do a perfect design the first time. What you really need to do is brainstorm and let your thought process go wild. Do not try to conform to any standards or conventions when trying to solve a problem, because the whole idea is to be creative. Thus, before you start to design a system, or even a class, think the problem through and have some fun! In this chapter we explore the fine art and science of OO thinking.
The move from the procedural world to an OO world is not trivial. Changing from FORTRAN to COBOL, or even to C, requires that you learn a new language; however, making the move from COBOL to C++, C# .NET, Visual Basic .NET, or Java requires that you learn a new thought process. This is where the
Three important things you can do to develop a good sense of the OO thought process are covered in this chapter:
We have already met some of these concepts in Chapter 1, and here we will now go into much more detail. |
| < Day Day Up > |