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 open up the computer and remove the drive and hold it in your hand. Both the computer and the drive are considered objects. It is just that the computer contains other objects such as drives.
In this way, objects are often built, or composed, from other objects: This is composition.
There is a lot to cover when discussing OO technologies. However, you should leave this set of three columns with a good understanding of the following topics:
- Encapsulation: Encapsulating the data and behavior into a single object is of primary importance in OO development. A single object contains both its data and behaviors and can hide what it wants from other objects.
- Inheritance: A class can inherit from another class and take advantage of the attributes and methods defined by the superclass.
- Polymorphism: Polymorphism means that similar objects can respond to the same message in different manners. For example, you might have a system with many shapes. However, a circle, a square, and a star are each drawn differently. By using polymorphism, you can send each of these shapes the same message (for example, Draw), and each shape is responsible for drawing itself.
- Composition: Composition means that an object is built from other objects.
We will explore these concepts and more in future columns.
About the Author
Matt Weisfeld is a faculty member at Cuyahoga Community College (Tri-C) in Cleveland, Ohio. Matt is a member of the Information Technology department, teaching programming languages such as C++, Java, and C# .NET, as well as various Web technologies. Prior to joining Tri-C, Matt spent 20 years in the information technology industry gaining experience in software development, project management, business development, corporate training, and part-time teaching. Matt holds an MS in computer science and an MBA in project management.
The articles in this series are adapted from The Object-Oriented Thought Process (published by Sams Publishing). Matt has published two other computer books, and more than a dozen articles in magazines and journals such as Dr. Dobb's Journal, The C/C++ Users Journal, Software Development Magazine, Java Report, and the international journal Project Management. Matt has presented at conferences throughout the United States and Canada.
Page 3 of 3