UML Object Models

Concepts

A UML object model is a package containing (i.e., owning) classes, interfaces, and sub-packages.

Interfaces own operations.

Classes own attributes, operations, associations, generalizations, and realizations.

An object model may contain one or more class diagrams.

A class diagram is a graphical representation (i.e., a view) of all or part of an object model.

Here's an example of a UML class diagram:

Notes

·       Class properties include: name, stereotype (<<entity>>, <<actor>>, etc.), isAbstract, isLeaf, isActive, etc.

·       Classes own attributes and operations.

·       Attributes properties include: name, type, visibility (+, -, #, ~), default value, isStatic, isLeaf, etc.

·       Operations properties include name, isStatic, isLeaf, and isAbstract.

·       Operations own parameters. Parameter properties include name, default value, and direction (in, out, in-out, return).

·       A generalization arrow connects a subclass to a superclass.

·       The "owns" association represents the relationship "Account holder X owns account Y" or equivalently: "Account Y is owned by account holder X".

·       An association owns two endpoints.

·       Endpoint properties include: name, reference (the class it connects to), visibility, multiplicity (1, 1..3, *, etc.), and navigability (true or false).

·       It's possible to generate class declarations from class diagrams. For example: accounts.

·        Here's a version with details provided (by the programmer): Bank.java.

·       Note that both attributes and associations translate into fields. Also note that administrative methods (constructors, getters, setters, delegators, toString, hashCode, equals, etc,) can be automatically generated.

Object Diagrams

Object diagrams are rarely used. The following diagram depicts the objects and links created by Bank.main:

Notes:

 Links are instances of associations in the same way that objects are instances of classes. We can combine these ideas and say that object diagrams are instances of class diagrams.

Object diagrams are class diagrams.

Object models can contain objects and links.

My use of the term "object model" to refer to a package containing classes and interfaces is a bit confusing and may not be standard, although I don't think I made it up. For me, an object model rarely contains links and objects. More typically it contains the classes that objects instantiate.

Models versus Views

·       A UML project owns one or more models.

·       A model owns many elements.

·       Elements include use cases, packages, classes, associations, diagrams, interactions, etc.

·       A model may own several diagrams. A diagram is one of many possible views of a model.

Owning versus Sharing

Objects can own or share other objects. (We avoid UML's aggregation and composition.)

Interfaces

An interface owns operations but not attributes or associations.

A class implements or realizes an interface if it implements all of the interface's operations.

If a class implements some of the interfaces operations, then it inherits the remaining operations as abstract operations and should be declared abstract.

 

Packages

Models are just packages.

A package diagram shows packages and their dependencies:

Containers

Technology

Class diagrams are one type of UML diagram.

The official UML specification comes from the Object Management Group ( http://www.omg.org/ ).

Class diagrams are created using CASE tools like StarUML (http://staruml.io/ ).

Lectures

·       UML Class Diagrams

Object Model Labs

Lab 1

Class Diagram Clinic

Lab 2

Improve Bank.java

Lab 3

Translating between code and class diagrams

Lab 4

UML Labs