|
 |
 |
[an error occurred while processing this directive]
CHAPTER 2 OBJECT ORIENTATIONTHEORY AND PRACTICE
How do I...
- 2.1 Understand the object-oriented paradigm?
- 2.2 Learn the concept of inheritance so that I can apply it programmatically?
- 2.3 Learn the concept of encapsulation?
- 2.4 Learn the concept of polymorphism?
Object-oriented programming is a very powerful and important programming paradigm. Object-oriented programs, when properly designed and implemented, provide more flexibility to meet the demands for delivering software in the rapidly changing marketplace. Everything from word processors, to spreadsheets, to graphics applications, to operating systems are written in object-oriented languages, the vast majority in C++.
This chapter introduces you to the concepts of the object-oriented paradigm. The target audience for this chapter is programmers working with procedural languages who are interested in moving to C++. It is suggested that this chapter be read before the chapter that follows. The chapter presents four How-Tos, each designed to provide you with knowledge of basic object-oriented concepts.
This chapter takes a unique approach in the presentation of a How-To. This chapter does not require the use of a special software tool. It does not require the use of any compiler or programming language. You might want to have a notepad or, if you prefer, a word processor. The focus for this chapter is centered on thinking, but thinking in an object-oriented way. The intent is to change your way of thinking about how a program is written. Object-oriented programming is very different from procedural programming. To effectively use an object-oriented language, you must make a paradigm shift.
2.1 Understand the Object-Oriented Paradigm
This How-To presents the common terminology used in object-oriented programming. Brief definitions for the most common terms are given. The How-Tos that follow will go into more detail about each of the terms and concepts.
2.2 Learn the Concept of Inheritance So That I Can Apply It Programmatically
Inheritance is one of three concepts that constitute the object-oriented paradigm. Inheritance implies a parent/child relationship, just as happens in nature. A pseudo programming language is defined in this How-To and is used in the How-Tos that follow.
2.3 Learn the Concept of Encapsulation
Encapsulation encompasses the interface and abstraction of a class. An encapsulated class is said to be cohesive or self-contained. Encapsulation provides a clean separation of interface and implementation of a class.
2.4 Learn the Concept of Polymorphism
Polymorphism literally means many (poly) forms (morph). An object exhibits polymorphic behavior based on its stance in an inheritance hierarchy. If two (or more) objects have the same interface, but exhibit different behaviors, they are said to be polymorphic. Polymorphism is a very powerful feature for an object-oriented language. It allows the behavior of a member function to vary depending on the type of the object.
2.1 Understand the object-oriented paradigm?
Problem
I understand the structured programming paradigm and am eager to move into object-oriented programming. I want to understand the object-oriented paradigm, including terms and fundamental concepts.
Technique
This How-To presents some of the fundamental terms and principles used to describe the concepts of object-oriented programming. Each term is defined in the Steps section that follows. You can use this How-To as a reference for the How-To sections that follow. Alternatively, use this How-To as a stepping stone to the How-Tos that follow.
Steps
This section defines common terminology used in object-oriented technology. You can think of this section as a reference, each step providing a definition for some object-oriented term or concept. In each of the How-Tos that follows, these terms will be described in more detail, building upon the basic definitions given here.
- AttributeThe data for a class that maintains the current state of an object. The state of an object is determined by the current contents of all the attributes. Attributes should be hidden from users of the object. Access to attributes should be defined through an objects interface.
- ObjectAn object is a something that exists and is identifiable. An object exhibits behavior, maintains state, and has traits. An object can be manipulated. Some examples of objects are telephones, automobiles, buildings, animals, and computers. An object is an instance of a class.
- ClassClass is synonymous with type. A class specifies the traits (data) and behavior that an object can exhibit. A class itself does not exist; it is merely a description of an object. A blueprint for a building is analogous to a class and the building itself is the object. A class can be considered a template for the creation of objects.
- InheritanceThis is the relationship of classes. There is an explicit is-a relationship between classes. For example, an automobile is-a vehicle, a zebra is-a mammal, a flower is-a plant, and so on. Classes with more specialization inherit from classes with more generalization.
- EncapsulationEncompasses the interface and abstraction of a class. An encapsulated class is said to be cohesive or self-contained.
- PolymorphismLiterally means many (poly) forms (morph). An object exhibits polymorphic behavior based on its stance in an inheritance hierarchy. If two (or more) objects have the same interface, but exhibit different behaviors, they are said to be polymorphic.
- InterfaceThe visible functionality of a class. The interface is the contract an object makes with users of an object. An interface emphasizes a classs abstraction. Users manipulate an object through its interface.
- ImplementationThe internal functionality and attributes of a class. A classs implementation is hidden from users of the class. Users should manipulate an object through its interface without regard to the objects implementation.
- AbstractionThe generalization of a class that distinguishes it from other classes. An abstraction emphasizes the interface of a class, providing a clean separation of its implementation.
|