L3 Class Diagrams Flashcards

1
Q

What is UML?

A

Unified Modelling Language

is a commonly accepted standard way to visualise the design of a software system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the use of UML?

A

UML, especially class diagrams:
○ OOP design patterns are typically drawn using class diagrams
○ Easier to fit more information in less space (e.g. compared to code)
○ Fast to create and reason about
○ “Lingua franca” in the OOP design world

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the perspectives of class diagrams

A

● Conceptual: focus on domain concepts, e.g. Bank, Account, ATM
● Specification: focus on the interfaces of Abstract Data Types (ADT)
● Implementation: focus on implementation details

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does an Association relationship mean in UML?

A

Two classes need to communicate with each other

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does an Aggregation relationship mean in UML? (Indicated by white diamond)

A

Implies that a class can exist without another class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does a Composition relationship mean in UML?

A

Implies that a class cannot exist without another class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Classes in UML

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Generalisation (inheritance)
Abstract Classes

A

● Abstract classes allow programmers to define methods without implementing them. All derived classes are then forced to provide implementations for these methods.

● Abstract classes and methods are italic

● Extends relationship is
used between the abstract class and its derived class (empty triangle from derived towards abstract class)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Type of generalisation(inheritance)

A

● There are two types of generalisation (inheritance) in OOP:
○ Interface inheritance
○ Implementation inheritance

● In Java, interface inheritance is achieved using interfaces

● Use implementation inheritance only if you want to reuse all methods (operations) of the parent class and add some extra methods to the derived class

● Otherwise do not use inheritance
● NB. a derived class in Java can inherit from only one parent class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Realisation (implements)

A

● In Java, realisation is achieved through interfaces

● Interfaces:
○ Contain only method signatures that describe the behaviour of a class (i.e. what behaviour a class needs to provide)
○ Class can implement multiple interfaces (i.e. a class can have multiple behaviours)
○ Class must match method signatures of all interfaces which it is implementing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Interfaces and abstract classes

A

● Interfaces and abstract classes are a cornerstone of OOP (key to software architecture)
● Interfaces/abstract classes:
○ Enable (dynamic) polymorphism
○ Reverse source code dependencies
○ Separate operations (important) from their concrete implementations (less important)
○ Form part of almost every software design pattern

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Multiplicity

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Steps to draw class diagrams

A

● Grammatical approach:
○ Classes and attributes are nouns:
■ Use tangible entities (things) in the application domain such as aircrafts, vehicles, servers, resources
■ Roles such as managers, customers, operators
■ Interactions such as meetings
■ Locations such as offices, companies etc.
○ Operations are verbs, i.e. actions carried out by a class

● Relationships:
○ Is the class a subclass of another? If so, the relationship is generalisation (inheritance).
○ Is the class part of another? If so, the relationship is aggregation or composition.
○ Does the class interact with another? If so, the relationship is association.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Grammatical approach example

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Grammatical approach example

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly