COMP0004-Notes(3): UML

8 篇文章 0 订阅

Models

What are models?

Representation of a system in the form of notations or a language

Modelling - the process of representing the system’s main behaviour, characteristics and states using a notation or language (Low-level: Java; High-level: UML).

Purpose of models?

  1. Show essential details
  2. Omit irrelevant details
  3. Show the communication of relevant information
  4. Demonstrate a form of Abstraction

Depending on different needs, we can have different levels of detail for a model.

Abstraction & Reification

Abstraction

The process of removing unnecessary details… making the model more abstract

Reification

The process of adding information, or implementing the model to make it a concrete, working model. This requires iterating through a number of intermediate models that are becoming more concrete, or building a system by progressively adding more details.

Diagrams

A Diagram is a partial representation of a model, depicting a part of the entire system. Usually need many types of diagrams to completely represent a system.

Can manifest a variety of aspects:

  • Structural elements: Class, Interface, Collaborations, Use case, Component.
  • Behavioural elements: Interaction (overview), State machine
  • Grouping elements: Package, Subsystem
  • Extension mechanisms: Profiles, stereotypes, tagged values
  • etc.

Next we look at a subset of them in somewhat further detail.

Structural Elements

Class Diagram*

Object Diagram

Use Case Diagram

Component Diagram

Deployment Diagram

Behavioural Elements

Interaction Diagram

Sequence Diagram

State Machine Diagram

Activity Diagram

Relationships

Relationships between classes are represented as links between class boxes in UML, and are realised by object references in Java.

Association

In standard UML, associations are, by default, bi-directional, as represented by these single links without arrows. Adding arrows makes it uni-directional.

Multiplicity

The term multiplicity 多重性 refers to the numberings labelled on the link:
在这里插入图片描述
In this case, the association is Has-Capital, and means that one and only one Country has the association Has-Capital with one and only one City, and vice versa (bi-direction).

If the numbering is replaced with something like 1…* or 0…*, this only means that a class has this association with multiple copies of another class. This can be implemented as a method returning an array of objects, or a method taking in multiple objects as argument. Therefore, this is not to be confused with Aggregation, which can only be represented as an instance variable holding an array of the other objects.

Aggregation

Aggregation means directly that an object holds multiple references to other objects as an attribute. Thus it should be implemented as a private instance variable.

In UML, Aggregation is given by the diamond symbol on the link.

Java Implementation

Although associations are typically defined as bi-directional, in Java, however, there is no way of enforcing such bi-directional connection, as the link can only be maintained by a uni-directional reference call. So remember to use the arrowed representation.

Returning null references

In implementations of associations, you will have to write methods that are not in the type void, which means that you will have to return a reference to an object, even when such object is not found. In this case you return an null reference, which seems natural.

However, on the client side, you must not forget this possible outcome, so after you call a getter method to have an object reference returned, you MUST NOT hurry on to carry out further operations on that reference. Instead, you MUST first check that the reference is not null, because operations on a null reference raises a NullPointerException, which crashes your client program!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值