What is the use of abstract classes

Abstract classes and methods

Abstract classes

In some applications an instantiation, i.e. an object creation, of a class is not desired, since the class is only intended to serve as a basic template for further classes. For this purpose are abstract classes has been introduced. They prohibit your own instantiation.

In the UML, abstract classes are identified by using an italic font. In the context of this course it is also possible to use the bracketed signal word "(abstract)" in front of the name.



Due to the fact that each series is a special composition of the most varied of components and is used to fulfill a wide variety of tasks, no specific instance of a robot should exist in this example. Each robot belongs to a special series. The robot class is therefore declared as abstract. Attributes and methods are however inherited depending on their visibility.


Polymorphism (abstract methods)

Polymorphism has also been introduced in connection with abstract classes. Polymorphism describes the possibility of storing a signature of a method in an abstract class. The actual functionality must be implemented in the subclass. The signature is therefore repeated in the subclass in any case (unless the subclass is again abstract). The signature of the abstract class will be abstract method called.



Each robot is switched on differently. In the 6 series, for example, only the control computer is supplied with power and the program installed there is executed. In the 7 series, on the other hand, various mechanical components have to be positioned first.

Since the robot class should remain generally valid, the "switch on" method is defined abstractly. The "switch on" method is adopted in each series, but the switch-on process must be defined explicitly.

Note: A class that contains an abstract method must automatically be declared as an abstract class, since the functionality of the method in a subclass must first be implemented.