The Unified Modeling Language (UML) Class Diagrams.

17
The Unified Modeling Language (UML) Class Diagrams

Transcript of The Unified Modeling Language (UML) Class Diagrams.

Page 1: The Unified Modeling Language (UML) Class Diagrams.

The Unified Modeling Language (UML)

Class Diagrams

Page 2: The Unified Modeling Language (UML) Class Diagrams.

Unified Modeling Language

• A standardized modeling language for the conceptualization and design of software systems

• Two types of diagrams: structure diagram and behavior diagram

• There are a lot of diagram types in the UML (14 types!) but we will focus only on a few in this class

Page 3: The Unified Modeling Language (UML) Class Diagrams.

Common Structure Diagrams

• Class Diagram– Illustrates classes, with attributes and methods, along with their

relationships– We will focus primarily on class diagrams, since they are by far the

most commonly used• Component Diagram

– Illustrates how components (each with an API or similar connecting interface) interfaces with other components

• Object Diagram– Illustrates the objects instantiated in a system at a single point in time

• Package Diagram– Illustrates the packages in a system and their dependencies

Page 4: The Unified Modeling Language (UML) Class Diagrams.

Common Behavior Diagrams

• Activity Diagram– A “flow chart” of sorts

• Interaction Diagram– The message sequence chart is one type of

interaction diagram• Use Case Diagram– Represents dependencies among use cases

• State Machine Diagram– Displays states and transitions

Page 5: The Unified Modeling Language (UML) Class Diagrams.

UML Diagrams are related

• Each diagram is a different view of a system

These classes belong to those packages.

Page 6: The Unified Modeling Language (UML) Class Diagrams.

A Class

Class/Object Name

Attributes

Methods/Operations

• A class name should be descriptive (Italic if abstract)• The attributes of a class defines its properties, what data the

class stores• The methods/operations of a class specify what the class does

Page 7: The Unified Modeling Language (UML) Class Diagrams.

Visibility of Attributes and Methods

Page 8: The Unified Modeling Language (UML) Class Diagrams.

Associations

Page 9: The Unified Modeling Language (UML) Class Diagrams.

Specific Associations: Aggregate

• Aggregations – “has a” relationships– A class is a container of other classes– Does not imply ownership, (ie. when the “parent”

gets destroyed, the aggregates do not)– Ex: A magazine has articles, but if the magazine

goes out of business, the articles don’t necessarily disappear (they may live on as part of another publication)

Page 10: The Unified Modeling Language (UML) Class Diagrams.

Specific Associations: Composite• Composition – combining simple objects into

a more complex whole– Can have multiple objects composed into one– Implies an “owns a” relationship– If the parent is destroyed, all its composites are

typically destroyed– Ex: If we delete the article we no longer care

about Facebook comments on the article

Page 11: The Unified Modeling Language (UML) Class Diagrams.

Difference between Composition and Aggregation

• Composition:– Composed of multiple parts– Parts have no independent existence– The structured whole makes the object

• Aggregation:– Does not imply ownership– Parts have independent existence– May be called a composition if the distinction is

not important

Page 12: The Unified Modeling Language (UML) Class Diagrams.

Generalization/Specialization

Generalization:“a parent”

Specialization:“a child”, inherits from a general class

Page 13: The Unified Modeling Language (UML) Class Diagrams.

Realization (Implementation)

• Relationship where one class (the client) implements another (the supplier)

• Represented with a dashed line from the implemented class to the implementation

Page 14: The Unified Modeling Language (UML) Class Diagrams.

Dependencies• A “using” relationship specifying that a change in the

specification of one thing may affect another thing that uses it

• Common when the client class:– Uses a supplier class that has global scope– Uses a supplier class as a parameter– Uses a supplier class as a local variable– Sends a message to the supplier

Page 15: The Unified Modeling Language (UML) Class Diagrams.

UML Examples

• This level of detail is usually reserved for the Design and Implementation phases– Deliverable 3: design– Deliverable 4: implementation

• You will not need to add all of these details in your Deliverables 2 or 3

Page 16: The Unified Modeling Language (UML) Class Diagrams.

Source: bigelow.ch

Page 17: The Unified Modeling Language (UML) Class Diagrams.

Combinations of UML Diagrams

• A class might have behavior attached to it• Behavior specified usually through a UML

activity diagram or a UML state diagram