UML Abstract Class vs Interface

What is the difference between an abstract class and an interface? This tutorial shows you similarities and differences between these two object-oriented programming concepts.

UML Abstract Class

An abstract class can contain abstract attributes and operations. The abstract members do not contain implementation. Unlike an interface, an abstract class can also include non-abstract members with implementation. An abstract class cannot be instantiated.

There is also another difference between the UML interface and UML abstract class. When a UML abstract class represents a class in single-inheritance object-oriented languages (as C# or Java) - a class can be inherited only from one abstract class, but it can implement multiple interfaces.

UML Abstract Class
UML Abstract Class

UML Interface

An interface is a classifier that contains attributes and operations without any implementation details. An interface cannot be instantiated. UML interface can be depicted in the same way as the UML class or using "lollipop" notation.

UML Interface
UML Interface

Comments

Vladimir Sekerka 7 January 2022 8:37:34

Namet na zlepsenie

Dobry den.

Z toho popisu nie je uplne jasny rozdiel. Aspon mne nie (som novacik v UML). Abstraktna trieda funguje nad dalsimi triedami bez toho aby vedela podrobnosti o implementacii (napr. trieda ktora vie triedit akekolvek pole, pokial je zadefinovany operator <) - t.j. abstraktna trieda moze obsahovat abstraktny kod. (?)

Pricom interface je len definicia, ze nejake rozhrania existuju, (t.j. trieda implementujuca tieto funkcie vie tieto funkcie pouzit pri svojom vypocte) ale musí existovat dalsia trieda, ktora dane funkcie naimplementuje. Napr. objekt pre archivaciu inych objektov.

Ake su typicke priklady pouzitia abstraktnej triedy a interface?

Z obrazku este nie je jasne, kedy sa pouziva pri interface notacia s gulockou a kedy s "C". a ako sa na priklade zakresli nejaky interface (na obrazku su len zobrazene prvky, ktore sa pri tom pouziju.

Dusan Rodina - softwareideas.net 10 January 2022 10:14:43

RE: Namet na zlepsenie

Dobry den,

dakujeme za pripomienky. Clanok rozsirime o dalsie detaily.

New Comment

Comment