Inheritance

Team-Fly

The concept of inheritance is what really makes OOP a powerful tool in application development. In OOP, inheritance simply means that classes can inherit the variables and methods of other classes. The classes that inherit these characteristics are called subclasses, and the class that is being inherited from is called the superclass.

A simple example of this hierarchy is in the computer industry, where you can have a Computer superclass with Desktop and Server subclasses, as shown in Figure 6.3. Both the Desktop and Server classes have many of the same variables and methods, and these common variables and methods can be assigned to the Computer superclass. Then the Desktop class will contain only variables and methods that are specific to the desktop, and the Server class will contain only variables and methods that are specific to the server.

Inheritance does not have to stop at one layer. Classes can be nested as deeply as required for the problem at hand. When the system is trying to resolve a variable or method name for a low-level subclass, it starts with the instance values. If it finds a value that matches the same name and type, the search stops; if a match is not found, the system looks in that class's superclass, and so on until the variable or method is found. From this information, we know that subclasses can override variables and methods from superclasses as long as the name and type declaration are the same.

click to expand

Figure 6.3: Class Hierarchy example

Inheritance allows the programmer to build abstract objects at a high level, and then to develop more detail about the object as the classes are developed down the class hierarchy. In the automobile industry, for example, you can have a class called Vehicle that defines many of the variables and methods common to all vehicles. Under Vehicle, you can have a class called Car that contains only the variables and methods that make cars distinct from other vehicles. Under the Car class, you can then define classes for sport, luxury, and economy cars; again, each class contains only the variables that make it unique under the Car class. If you need to define a new type of car, for example electric, you can simply add a new class under the Car class. Most of the work is already completed. Because an electric car is not too different from a regular car, your only job is to define the Electric class with the variables and methods that make it unique in the Car superclass.

Does This Terminology Sound Familiar?

Even if you have never used OOP, you might recognize a lot of the concepts and terminology in this chapter. SAP's variant configurator is based on object-oriented design. Dependency rules are the methods, characteristics are the variables, and SAP's classes and class hierarchy fit the OOP mold exactly. Of course, the flip side is also true; if you do not have any experience with SAP's variant configuration module, you can now say that you understand the basics of how it works!


Team-Fly


Java & BAPI Technology for SAP
Java & BAPI Technology for SAP
ISBN: 761523057
EAN: N/A
Year: 1998
Pages: 199

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net