Implementation of UML concepts in Java

Categories:

Recommended

UML – Class Diagram

 Class diagram depicts the static structure of the system. This structure comprises:

  • The classes
  • The associations between classes
  • The dependencies between classes
  • System interfaces

Class

The UML symbol for a class is a box with three partitions. In the top partition we write the name of the class. In the middle partition the attributes of the class and the third partition the class methods. In the example of the figure, the name of the class is ‘Student’. The class has a ‘name’ attribute and an ‘enroll’ method.

Association

Associations are relations between instances of a class (A person works for a company. A company has a number of employees). Associations in UML are depicted as lines connecting the associated classes. In the example diagram, class Student is associated with the Course class.

Role

An association end can be named with a label. This label is the rolename and represents the role of the end’s class in the association.

Multiplicity

An association end has also a multiplicity, which is an indication of how many instances can participate in this association at any time. Multiplicity can be exactly 1, 0..1 (optional association), * (zero or more), 1..* (one or more), or any specific number.

Navigability

Navigability represents the ability to traverse an association from one direction, but not the opposite direction. For example consider the UML class diagram of the figure. The arrow in the Professor-Course association means that having a professor instance we can query it for the its courses but not the opposite (course instances are unaware of the professors that teach them). Therefore the navigability is from the professor to the course. Student courses

Generalization

Generalization is a technique that allows the definition of a general class from which more specific classes are derived. These more specific classes (subclasses) specialize certain aspects of the more general class (base class or superclass). In the figure we can see a generalization example in which a Part-Time Student is defined as a subclass of the more general Student base class.

UML – Sequence Diagrams

In UML sequence diagrms objects are represented as boxes placed horizontally from left to right. Objects exchange messages that are depicted as directed arrows. The direction of arrows shows the direction of the message (which object is the source of the message and which object is the destination of the message). Time passes from top to bottom: messages higher on the sequence diagram occur before messages lower on the diagram.

Object

An object is represented by a box in which we write the name of the object and the class of the object separated by a colon. If we haven’t decided yet what is the class of an object we can omit the class name. If the name an object is not important we can omit it and simply write the class name preceded by the colon.

Message exchange

Message exchange is represented as a directed arrow from one object (the sender) to another object (the receiver). Message handling is provided by the receiver object implementation. The receive object will usually provide a method that will handle the message. In the sequence diagram example of the figure, class Customer will provide a public method ‘getName()’ that will be executed when the message arrives at the aCustomer object. If the message is conditional we write the condition of the message before it in brackets (e.g. [ok]getName()). If the message is repeated (as in loops) we write an asterisk before the message (as in * getName()).

Message Return

A message return is depicted as a dashed arrow from the receiver of the message back to the sender, and it means that the receiver finished processing the message. If there are any results, they can be written above the dashed line. It is not obligatory to explicitly draw returns from messages and we usually omit them.

Self calls

Self-calls are method calls in which the sender and the receiver objects are the same object.

Category:
Tag:

Attribution

Kakarontzas George. Implementation of UML concepts in Java. http://users.teilar.gr/~gkakaron/oose/04.pdf

Source of the article: Wikipedia

VP Flipbook Maker

This flipbook was made with the free flipbook maker from Visual Paradigm Online, you can also develop a book like this. Create online flipbooks, design, publish and share your flipbooks online, try it now!