CS3342 Lecture 4
UML - Class diagram
A class diagram is used to visualize object-oriented classes and their relationships in our system.
![](https://images2018.cnblogs.com/blog/1307302/201803/1307302-20180322113553389-2057640378.png)
Class Linkages – 3 Types
Composition - <black diamond>
A has B (B Must be included)
Implementation: Class_A contains a fixed local variable links to Class_B
Aggregation - <white diamond>
A has B (B is Optional, can be included later)
Implementation: Class_A contains a changeable local variable links to Class_B
Association
A uses B (can define B at runtime, more dynamic)
Class_A DO NOT contain a local variable links to Class_B
Class_A uses Class_B as (input/output) Parameter directly.
Example:
![](https://images2018.cnblogs.com/blog/1307302/201803/1307302-20180322114411177-929315379.png)
in BlueJ
Association &Multiplicity
Example1:
A (1) Car has (Must) four (4) Wheels. (Contains 4x “Wheel” object instances) - Use a container such as Array, ArrayList.. etc
Example2:
UML - Use Case diagram
Use Cases – visualize functional interactions
Typically, a use case is a contract of an interaction between the system and an actor.
The Actor can be a human or an external system / machine.
A full use-case model comprise of:
–A Use Case Diagram, describing relations between use-cases (system tasks, roles) and actors (external parties).
–Use Case Specifications (usually one per each use case) - Documents describe the use case in details
Use Cases as Means of Communication in real world
The use case should stimulate a discussion about what the system should do, mainly with people who are outside of the development team.
Use Case Diagram Objective
1. Create a semi-formal model of the functional requirements (What the system does…)
2. Analyze and define:
–Scope (What are the main functions?)
–External parties (who will interact with the system?)
–External interfaces (how they are related?)
–Scenarios and reactions (One Big Picture)
Steps to Build an Use-Case Model
- Choose the system boundary – what are you modeling? System? Business organization?
- Identify the primary actors – they have user goals fulfilled by using the services of the system
- For each primary actor, identify their user goals – define what they want to do with the system. Describe their goals at the correct level
- Define use cases that satisfy user goals. Name each according to its goal. [You may find out other actors, which we call secondary actors of that particular use case.]
Find Actors
External objects(Must be external to the system) that produce/consume data(Must serve as sources and destinations for data):
- human/system outside the system that interacts with the system
- provides input to or takes output from the system
- a role the user can play multiple roles possible
Eg: Humans, Machines, External Systems, Sensors, Organization Units...
Note: Database and Printer are NOT actors
Primary actor - interacts directly with the system
Secondary actor - interacts indirectly with the system or support the use case to complete a use case for the primary actor
![](https://images2018.cnblogs.com/blog/1307302/201803/1307302-20180322121726593-1933909885.png)
Three Basic Types of Relationship in Use Case Model
Association
Instances of the actor and instances of the use case communicate with each other
The only relationship between actors and use cases
<<Include>> Relationship
Allow one to express commonality between several different use cases.
Can be included in other use cases
Even very different use cases can share sequence of actions.
Enable you to avoid repeating details in multiple use cases.
Shows the performing of a lower-level task with a lower-level goal.
![](https://images2018.cnblogs.com/blog/1307302/201803/1307302-20180324170837426-2142098617.png)
<<Extend>> Relationship
Use it to show optional behavior explicit or to handle exception scenarios
Keep the description of the basic use case simple.
The base use case can incorporate another use case at certain points, called extension points. (IF… THEN… )
![](https://images2018.cnblogs.com/blog/1307302/201803/1307302-20180324171011906-1228759490.png)
Example:
![](https://images2018.cnblogs.com/blog/1307302/201803/1307302-20180324170941111-969285713.png)
Generalization(Inheritance)
A generalization from use case A to use case B indicates that A inherits B.
![](https://images2018.cnblogs.com/blog/1307302/201803/1307302-20180322122934799-1734949207.png)
Actors can also be generalized
Guidelines for Effective Use Cases
Number Limit:
The diagram should have between 3 to 10 base use-case. No more than 15 use cases (base + included + extending).
Abstraction:
All use-cases should be in similar abstraction levels.
Size:
Use cases should be described in half a page or more.
Weak dependency:
If the dependency between two parts of a use-case is weak, they should be splitted.
Factor out common usages that are required by multiple use cases:
If the usage is required use <<include>>
If the base use case is complete and the usage may be optional or conditional consider use <<extend>>
A use case diagram should:
contain only use cases at the same level of abstraction
include only actors which are required
Writing Use Cases
.....