Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

RE:ABAP objects

alex_georgek
Associate
Associate
0 Likes
549

Hi,

Can any one explain with a simple example what you mean by

class,subclass,superclass...

Thanks & regards,

Alex.

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
529

If A is a subclass of B, then B is the superclass of A.

A class is an encapsulation of a concept, perhaps some physical object like a vehicle, or a business object like a purchase order, or something more abstract like BW start routine. A subclass is more specific than its superclass. A superclass is more general than its subclasses. ( In ABAP a class can have up to one superclass, though type OBJECT can be considered a superclass of all classes, except itself ).

For example, you may have a class representing VEHICLES. It could have two subclasses CAR and BICYCLE. ( So VEHICLES would be the superclass of both CAR and BICYCLE ). The class VEHICLES would have all the attributes and methods that apply to all kinds of vehicles - e.g. "source of power". The CAR class would inherit all the VEHICLE attributes and methods, and have additional methods and attributes applicable only to cars - e.g. "number of doors". Similarly for the BICYCLE, you might have "pedal_type". Both CAR and BICYCLE would have "source of power", as they've inherited this from VEHICLES.

matt

4 REPLIES 4
Read only

matt
Active Contributor
0 Likes
530

If A is a subclass of B, then B is the superclass of A.

A class is an encapsulation of a concept, perhaps some physical object like a vehicle, or a business object like a purchase order, or something more abstract like BW start routine. A subclass is more specific than its superclass. A superclass is more general than its subclasses. ( In ABAP a class can have up to one superclass, though type OBJECT can be considered a superclass of all classes, except itself ).

For example, you may have a class representing VEHICLES. It could have two subclasses CAR and BICYCLE. ( So VEHICLES would be the superclass of both CAR and BICYCLE ). The class VEHICLES would have all the attributes and methods that apply to all kinds of vehicles - e.g. "source of power". The CAR class would inherit all the VEHICLE attributes and methods, and have additional methods and attributes applicable only to cars - e.g. "number of doors". Similarly for the BICYCLE, you might have "pedal_type". Both CAR and BICYCLE would have "source of power", as they've inherited this from VEHICLES.

matt

Read only

Former Member
0 Likes
529

hi,

That is the concept called Inheritence in OO Programming.

INHERITANCE

Inheritance is an implementation relationship between classes that allows a class, called a subclass, to inherit all components of another class, called a superclass. In ABAP Objects, adding INHERITING FROM to the class definition statement enables inheritance .

In a subclass you define additional components or redefine instance methods that were inherited from the superclass, but you can't remove inherited components. Therefore, a subclass is strongly coupled to its superclass just by containing all of the superclass's components. While a subclass knows its superclass, a superclass has no knowledge of its subclasses. Nevertheless, the semantic coupling is strong in both directions because changing a superclass automatically changes or even invalidates all of its subclasses.

While a subclass specializes a superclass by adding components or redefining methods, a superclass is a generalization of its subclasses. In fact, inheritance should be used to implement relationships between classes that can be described in terms of generalization and specialization. For example, if you compare a passenger_airplane class to a cargo_airplane class, you will find that many common features can be put into a general superclass, airplane.

Hope you got something out of the explaination.

regards,

theja

Read only

Former Member
0 Likes
529

Hi Alex,

just go through this link,

http://www.erpgenie.com/abap/OO/index.htm

Hope this helps.