Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In an UML diagram, when should a class be abstract?

In an UML diagram, when should a class be abstract? Just when we want to prevent instantiation?

Edit: Can an abstract class fully implement a method (when the method only depends on the attributes of that abstract class)?

like image 312
John Assymptoth Avatar asked Feb 05 '11 12:02

John Assymptoth


People also ask

What is an abstract class in UML?

An abstract class is a template definition of methods and variables of a class (category of objects) that contains one or more abstracted methods. Abstract classes are used in all object-oriented programming (OOP) languages, including Java (see Java abstract class), C++, C# and VB.NET.

How do you indicate that a method is abstract in a UML class diagram?

Abstract methods are displayed by italic text (UML has a boolean value for this). The notation you are using is called Keyword (simple way) or Stereotype (more complex).

How do we represent an abstract class and interface UML?

(Note: In UML, abstract methods/classes are denoted by slanted text, specialization is denoted by an arrow with a solid line, and realization/implementation of an interface is denoted by an arrow with a dashed line.)

Is UML a form of abstraction?

An abstraction of a system is a model of the system that includes all the details about the system. UML diagrams are a form of abstraction, since they hide details and allow us to concentrate just on the major design components.


2 Answers

Preventing instantiation is a matter of implementation, so it is a good reason if you are thinking in terms of Java, C# etc.

However, on the level of modelling, you'd want to make a class abstract if there are several subclasses, and it makes no sense that an object is of the supertype but of neither of the subtypes.

So, basically you're not preventing instantiation of the class, since any instance of the subclass is also an instance of the abstract superclass. What you are doing in that case is preventing instantiation of the superclass alone, i.e. enforce using one of the subtypes.

Answer to EDIT: Yes!

like image 140
Goran Jovic Avatar answered Sep 20 '22 03:09

Goran Jovic


A class is abstract if it has one or more operations that are abstract.

In UML indicate abstract with italics or {abstract}.

The following diagram (which is on page 70 of my UML Distilled Third Edition book by Martin Fowler) shows how and why to denote abstracts: enter image description here

like image 41
amelvin Avatar answered Sep 22 '22 03:09

amelvin