What is UML?
Ans:
“The Unified Modeling Language (UML) is a language for specifying, visualizing, constructing, and documenting the artifacts of software systems, as well as for business modeling and other non-software systems”.— OMG UML Specification.
“UML is a graphical notation for modeling various aspects of software systems.” — William H. Mitchell (whm)
Why use UML?
Why use a graphical notation of any sort?
Facilitates construction of models that in turn can be used to:
- Reason about system behavior
- Present proposed designs to others
- Document key elements of design for future understanding
Which graphical notation should be used?
UML has become the de-facto standard for modeling object oriented systems.
- UML is extensible and method-independent.
- UML is not perfect, but it’s good enough.
What are the different types of UML Diagrams?
Ans:
There are several types of UML diagrams:
Use-case Diagram
Shows actors, use-cases, and the relationships between them.
Class Diagram
Shows relationships between classes and pertinent information about classes themselves.
Object Diagram
Shows a configuration of objects at an instant in time.
Interaction Diagrams
Show an interaction between a group of collaborating objects.
Two types: Collaboration diagram and sequence diagram
Package Diagram
Shows system structure at the library/package level.
State Diagram
Describes behavior of instances of a class in terms of states,stimuli, and transitions.
Activity Diagram
Very similar to a flowchart—shows actions and decision points, but with the ability to accommodate concurrency.
Deployment Diagram
Shows configuration of hardware and software in a distributed system.
Class diagram basics :
Consider a simple class to represent a point on a Cartesian plane:
1 2 3 4 5 6 7 |
class Point { private double x, y; Point(double x, double y) { this.x = x; this.y = y; } public double getX( ) { return x; } public double getY( ) { return y; } public double getDistFromOrigin( ) { ... } } |
The corresponding UML class diagram:
Three compartments are shown: class name, attributes, operations.
Member visibility is indicated with + (public) and – (private); these are called visibility adornments.
UML permits the detail of a diagram to vary based on the intended use. The compartments with attributes and/or operations can be omitted.
Here is a less detailed diagram for the Point class:
Here’s a version with only the operations shown:
Here is a class that represents rectangles using a point, a width, and a height:
1 2 3 4 5 6 7 |
class Rectangle { private double width, height; private Point ULCorner; public Rectangle(Point ULC, double w, double h) { ... } public double getArea() { ... } public Point getCenter() { ... } } |
A class diagram showing the relationship between Rectangle and Point:
The link between Rectangle and Point indicates:
- There is a field in Rectangle that references a Point.
- Point has no knowledge of Rectangle. (We’d expect no references to Rectangle in the source for Point.)
- Point’s role with respect to Rectangle is that of “ULCorner”.
Class diagrams—aggregation
When a class may reference several instances of another class, the link between the two classes is shown with a diamond on the end of the aggregate class.
Here is a class diagram showing the relationships between Triangle,Polygon, Rectangle, and Point classes:
It can be seen that:
- An instance of Triangle references three instances of Point.
- An instance of Polygon references at least one, and a potentially unlimited number of Point instances.
- Aside from Triangle, Polygon, and Rectangle knowing of Point, no classes have any knowledge of any other classes.
Note that “3” and “1..*” are multiplicity specifications.
Object diagrams
An object diagram shows a configuration of objects at a point in time.
After execution of this code,
Point corner = new Point(3,4);
Rectangle r = new Rectangle(corner, 5, 10);
the situation can be depicted with this object diagram:
If desired, various elements may be omitted:
Note that an underlined name in the name compartment is the indication that an object is at hand.