Week 5
Week 5
Engineering 1
Week 5
Class Diagram
1.Class diagrams are a type of static structure diagram that describes the
structure of a system by showing the system's classes, their attributes,
operations (or methods), and the relationships among objects.
2.The class diagram is the main building block of object-
oriented modeling.
3. Classes represent an abstraction of entities with common
characteristics.
• Relationship Types
1- Associations
• Associations represent static relationships between classes
2- Multiplicity
o Place multiplicity notations near the ends of an association. These symbols indicate the
number of instances of one class linked to one instance of the other class.
For example, one company will have one or more employees, but each employee works for
one company only.
3- Generalization
• A special type of aggregation where parts are destroyed when the whole
is destroyed.
• Class2 cannot stand by itself.
• Composition display relationship where the child will never exist independent of
the parent. Example: House (parent) and Room (child).
8
Example 1:
This is a simple UML class diagram example that shows the use of various
UML relationships in a class diagram.
• Draw a class diagram for a graphic editor, which supports the concept of
grouping.
• Assuming that a document has several pages, every page contains the
following graphic objects: text, geometrical objects, and groups.
Geometrical objects are e.g. circles, ellipses, rectangles, lines and squares.
A group is simply a set of graphic objects, which can contain further groups
for its part.
A group has to contain at least two graphic objects. A graphic object can be
a direct member of at most one group
Example
•UML class diagram which shows a domain model for online shopping. The purpose of the diagram is to
introduce some common terms, "dictionary" for online shopping - Customer, Web User, Account,
Shopping Cart, Product, Order, Payment, etc. and relationships between. It could be used as a common
ground between business analysts and software developers.
• Each customer has unique id and is linked to exactly one account. Account owns shopping cart and
orders. Customer could register as a web user to be able to buy items online. Customer is not required
to be a web user because purchases could also be made by phone or by ordering from catalogues. Web
user has login name which also serves as unique id. Web user linked to a shopping cart. Shopping cart
belongs to account.
• Account owns customer orders. Customer orders are sorted and unique. Each order could refer to
several payments, possibly none. Every payment has unique id and is related to exactly one account.
Both order and shopping cart have line items linked to a specific product. Each line item is related to
exactly one product. A product could be associated to many line items or no item at all.