You are on page 1of 18

UML – CLASS DIAGRAM

CUONG V. NGUYEN - SE 2020


AGENDA
▪ Class diagram
▪ Relationships between classes
▪ Usage of class diagrams
▪ Some best practices
▪ Exercise

CUONG V. NGUYEN - SE 2020


CLASS DIAGRAM
▪ Class diagram in the Unified
Modeling Language (UML) is 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
▪ Class diagram can be used for
visualizing and documenting different
aspects of a system, or also for code
generation
CUONG V. NGUYEN - SE 2020
CLASS
▪ A description of a group of objects all with similar features in the system
▪ A Class is a blueprint for an object

CUONG V. NGUYEN - SE 2020


WHAT OTHER CLASS CAN YOU THINK OF?

CUONG V. NGUYEN - SE 2020


CLASS ATTRIBUTES
Class Name
▪ The name of the class appears in the first partition.
Class Attributes
▪ Attributes are shown in the second partition.
▪ The attribute type is shown after the colon.
▪ Attributes map onto member variables (data members) in code.
Class Operations
▪ The return type of a method is shown after the colon at the end of the method signature.
▪ The return type of method parameters is shown after the colon following the parameter name.
▪ Operations map onto class methods in code

CUONG V. NGUYEN - SE 2020


SAMPLE

CUONG V. NGUYEN - SE 2020


SAMPLE

CUONG V. NGUYEN - SE 2020


VISIBILITY

Access Right Public + Private - Protected # Package ~


Within class yes yes yes yes
Sub classes yes no yes yes
in same
Other classes yes no no
package

CUONG V. NGUYEN - SE 2020


IN OO PROGRAMMING
▪ What are the issues? Can we make it better

CUONG V. NGUYEN - SE 2020


RELATIONSHIPS
1. Dependencies

2. Generalizations

3. Associations

CUONG V. NGUYEN - SE 2020


ASSOCIATIONS
▪ Relationships between objects are
described by Associations
▪ Aggregation: when we say an object is
made up from several other
independent parts.
▪ Composition: can we say that
something is part of something else with
the same life cycle? then there's a good
chance for composition.

CUONG V. NGUYEN - SE 2020


AGGREGATION VS. COMPOSITION
Aggregation Composition

• Aggregation indicates a • Composition display relationship


relationship where the child can where the child will never exist
exist separately from their parent independent of the parent.
class.
• Example: iPhone and its charger.
• Example: CD Player (Parent) and Pretty much you can’t use the
a CD (Child). So, If you don’t have charger with other type of phone
the Music Player, the child CD still (till now).
exists and you can use it
somewhere else.
CUONG V. NGUYEN - SE 2020
CARDINALITY
Indicator Meaning
0..1 Zero or one
1 One only
0..* Zero or more
1..* One or more
n Only n (where n > 1)
0..n Zero to n (where n > 1)
1..n One to n (where n > 1)
CUONG V. NGUYEN - SE 2020
USAGE

Conceptual Specification Implementation

▪ Conceptual: describes the high-level concepts in the domain


▪ Specification: focus is on the interfaces and abstract data type in the
software
▪ Implementation: describes in detail the attributes, operations of the classes

CUONG V. NGUYEN - SE 2020


BEST PRACTICES
▪ Use meaningful name to describe the real aspect of the system.
▪ Avoid creating large diagrams, break them down into smaller ones if possible.
▪ The responsibility for every class needs to be properly defined. Colors can make a
different.
▪ Avoid crossing lines in relationships. The more lines overlap on your class diagrams,
the more cluttered it becomes.
▪ Try to use minimum number of properties. Not needed properties (at the point) can
easily make the diagram complicated.
▪ Class diagrams are used for a wide variety of purposes – be aware to apply a
different style in each circumstance.
CUONG V. NGUYEN - SE 2020
SUMMARY
▪ The class diagram one of the main building blocks of object-oriented
modeling.
▪ A class is a blueprint for an object.
▪ Relationships between classes are used to depict the types of logical
connections or relations between them.
▪ Class diagrams can be used for variety of purposes from general
conceptual modeling of the structure of the application, to detailed
modeling to support code generation.

CUONG V. NGUYEN - SE 2020


EXERCISE
▪ Draw class diagram for ATM, entities are: Account, Checking Account, Saving
Account, ATM, Customer, Bank, Transaction.

CUONG V. NGUYEN - SE 2020

You might also like