Software Engineering
Class Modeling

Course Map

Agenda


Class Diagrams

A Class diagram gives an overview of a system by showing its classes and the relationships among them. Class diagrams are static -- they display what interacts but not what happens when they do interact.

The class diagram below models a customer order from a retail catalog. The central class is the Order. Associated with it are the Customer making the purchase and the Payment. A Payment is one of three kinds: Cash, Check, or Credit. The order contains OrderDetails (line items), each with its associated Item.

Class diagram

UML class notation is a rectangle divided into three parts: class name, attributes, and operations. Names of abstract classes, such as Payment, are in italics. Relationships between classes are the connecting links.

In UML a feature characterizes the instances of a classifier or the classifier itself.


Attributes

A structural feature of a classifier that characterizes instances of the classifier. An attribute relates an instance of a classifier to a value or values through a named relationship.

Attributes by Relationship


Operations

 


Relationships

Our customer order class diagram has three kinds of relationships.

An association has two ends. An end may have a role name to clarify the nature of the association. For example, an OrderDetail is a line item of each Order.

A navigability arrow on an association shows which direction the association can be traversed or queried. An OrderDetail can be queried about its Item, but not the other way around. The arrow also lets you know who "owns" the association's implementation; in this case, OrderDetail has an Item. Associations with no navigability arrows are bi-directional.

The multiplicity of an association end is the number of possible instances of the class associated with a single instance of the other end. Multiplicities are single numbers or ranges of numbers. In our example, there can be only one Customer for each Order, but a Customer can have any number of Orders.

This table gives the most common multiplicities.

Every class diagram has classes, associations, and multiplicities. Navigability and roles are optional items placed in a diagram to provide clarity.


Generalization, Association, Aggregation, and Composition

Each of UML relationships represents a different type of connection between classes and has subtleties that aren't fully captured in the UML specification. Be sure that your intended viewers understand what you are conveying with your various  relationships.

Notice that with both types of aggregation, the diamond is located on the side of the line pointing to the aggregate class which represents the "whole" in an aggregation (whole-part) relationship.

The following is a handy short-cut guide:

Dependency
Association
Aggregation
Composition
Generalization
"...uses a..."
"...has a..."
"...owns a..."
"...is part of..."
"...is a..."

Object Diagrams

Object diagrams show instances instead of classes. They are useful for explaining small pieces with complicated relationships, especially recursive relationships.

This small class diagram shows that a university Department can contain lots of other Departments.

Recursive class diagram

The object diagram below instantiates the class diagram, replacing it by a concrete example.

Object diagram

 

Each rectangle in the object diagram corresponds to a single instance. Instance names are underlined in UML diagrams. Class or instance names may be omitted from object diagrams as long as the diagram meaning is still clear.


Composite Structure Diagrams

A composite structure diagram depicts the internal structure of a classifier in terms of parts.

Part
An element representing a set of instances by composition that are owned by a containing classifier instance or role of a classifier. All such instances are destroyed when the containing classifier is destroyed. Parts may be joined by attached connectors and specify configurations of linked instances to be created within an instance of the containing classifier.

 


Properties in a class diagram and in a structure diagram

A property specifying an instance not owned by composition by the instance of the containing classifier is shown by a graphical nesting of a box symbol with a dashed outline.

Property examples
The namestring of a part obeys the following syntax: <name>‘:’<classifiername> [multiplicity]


Properties in a structure diagram


Connectors and parts in a structure diagram


Connectors and parts in a structure diagram using multiplicities

 


An instance of the Car class

The namestring of a role in an instance specification obeys the following syntax:
{<name> [‘/’ <rolename>] | ‘/’ <rolename>} [‘:’ <classifiername> [‘,’ <classifiername>]*]
The name of the instance specification may be followed by the name of the part that the instance plays. The name of the part may only be present if the instance plays a role.

More details

Self test


Packages

Examples of packages with members
 

To simplify complex class diagrams, you can group classes into packages. A package is a collection of logically related UML elements. The diagram below is a business model in which the classes are grouped into packages.

 


Packages and Dependencies

Packages appear as rectangles with small tabs at the top. The package name is on the tab or inside the rectangle. The dotted arrows are dependencies. One package depends on another if changes in the other could possibly force changes in the first.


Packaging Rules

How do you chose which classes to put in which package?


Public and Private Package Imports


 


Packages - Comments


Self test


Documenting Classes