1.3: Fundamental Concepts of Object-Oriented Programming
As
we saw in 1.1, object-orientation has nothing to do with computer
languages, although such languages can be used to implement such
worldviews for computer applications. Once you gain the knowledge and
experience to see take a larger view, to see beyond the syntax of a
particular language, you will gain the ability to debug programs written
in languages you have never seen before. In this subunit, we dig deeper
into the object-oriented perspective and its implementation in Java and
C++.
- Object-Oriented (OO) concepts of modularity, abstraction, composition, and hierarchy are very powerful and require intense attention to detail. This chapter gives a detailed presentation of OO as implemented by Java. The terminology in this article is a little different; name-binding is called name-scope. The chapter begins with an explanation of the data and procedures of a class (called class variables and class methods). The class data can be fixed for all objects, in which case, it is called static. Static variables are common to all objects. There is only one copy and, thus only one value, stored in the class.
A name (variable) is associated with a 'value'. A Java class can have any number of variables and each object (instance) of the class contains its own copy of those variables. In the terminology for Java, each object has a name, which is a pointer to the location of each instance of an class, and its variables. The next detail to note is how objects are created and initialized (i.e. values assigned to its instance variables and its methods names) by assigning values to them in the class via constructors.
A consequence of the concepts of modularity and abstraction is reuse. In writing an OO program we can use classes that have been written by others and are part of the language or contained in class libraries associated with the language. Recall that the generic computing paradigm consists of several states: requirements, design, implementation, and validation. In software engineering, it is referred to as the programming process.
Section 5.3 gives insight into writing programs using classes. What classes, what objects, and how they are related are questions of program design. Section 5.4 illustrates the design and implementation stages of the process. The latter sections continue with the VERY important OO details of inheritance and polymorphism. They create a class hierarchy that enables code to be shared among classes and among similar, but different, objects. Whereas Java has simple inheritance (a subclass can extend one superclass), C++ has multiple inheritance ( a subclass can extend 2 or more superclasses). Java does, however, have a restricted kind of multiple inheritance called interfaces, where an interface can be implemented by 2 or more classes. As you read, think about how the concepts are connected. If you understand variable names, in particular the object names 'this' and 'super', the class name 'Object', and the dot naming convention (like ClassName.objectName.methodname), you should have a good understanding of the concepts and details presented in this article.
1.3.1: Practice Using Classes and Objects
Read this text on the implementation of classes, methods, attributes, and driver programs.
1.3.2: Practice Using Inheritance
Read this article, and then take a shot at an implementation using inheritance. The text gives a detailed walkthrough of one approach.