Nicholas Chan
Nicholas Chan

Reputation: 401

How do we draw abstract method in uml class diagram

public abstract class Shape {   
    abstract int area();
}

How do we draw the UML class diagram for the abstract method? Use +, - or #?

public class Room { 
    int nWindows;   
}

And what if the class instance variable doesn't have public, private or protected?

Upvotes: 14

Views: 24433

Answers (1)

Ister
Ister

Reputation: 6318

Abstract

According to UML specification:

The name of an abstract Classifier is shown in italics, where permitted by the font in use. Alternatively or in addition, an abstract Classifier may be shown using the textual annotation {abstract} after or below its name.

Note however that Operation is not a Classifier. It still has an isAbstract attribute as a BehavioralFeature but 2.5 specification does not define how to model the fact of being abstract. Older specifications (1.4.x) were using the same method as for Classifiers and it is a widely recognized method to show operation abstraction. Note only that the elements in curly brackets for features are presented at the end of line rather than just after the name (Classifier simply has no other specification directly after name).

Possibly authors made an omission in 2.5 specification for Feature abstraction notation by a mistake.

An abstract operation can of course have any visibility kind.

Of course the operation might be abstract only if its containing Classifier (Class in your case) is also abstract.

No visibility kind

In general visibility kind in UML is optional i.e. you can simply omit it. Just take into consideration that UML is a model so it actually can ignore some irrelevant elements or can specify them at a later stage of modelling. Not using any visibility kind in UML does not allow you to make any assumption about it's final visibility kind.

On the other hand if in actual code you use no visibility kind specification (if allowed at all) there is some default behaviour. For example

  • in Java it's package (#) - in UML understanding, Java calls it "package-private",
  • in C++ you'll end up with private feature (-),
  • in PHP such features are treated as public (+)

and so on.

Upvotes: 14

Related Questions