2-COE312 Lecture - Class diagrams
2-COE312 Lecture - Class diagrams
and Modifiers
Omar Arif
A Class diagram depicts classes and
their relationships
Class
It depicts a static view of an
Diagram
application
Customer
Rental Invoice
Diagram
Checkout Screen
Bicycles E. Scooter Tricycle
Each class is represented by a rectangle
subdivided into three compartments
Name
Attributes/Fields
Methods
Generalizati Example:
Animal
on
Relationship <<Interface>>
Pet Mammal
s
Cat Dog
It represents a has-a relationship between two
classes, where one class is associated with
another class.
Student enrolls in a course
Courses have students
Courses have exams
Student Course
Association
Relationship
Associations can be further classified
as
Aggregation
Composition
Aggregation is a type of association that
represents a whole-part relationship between two
classes, where one class is the owner of another
class, but the contained class can exist
independently of the owning class.
Aggregation
The composition is a strong type of association,
where one class is made up of one or more
instances of other classes. It portrays the
Composition dependency relationship, where the lifetime of the
contained class is dependent on the owning class.
Customer
Aggregation
Class
Rental Invoice
Abstract
Class
Class <<abstract>>
Diagram
Rental Item
Composition Simple
Generalization Association
Checkout Screen
Bicycle Quad Bike Dune Buggy
Access Modifier
public: class is accessible for any
Modifiers: class
Class Default: class is only accessible
by classes in the same package
Non-Access Modifier
final: attributes and method
cannot be overridden/modified
Modifiers: static: only permissible for nested
Class classes
abstract: Can only be used in an
abstract class, and can only be
used on methods
Access Modifiers:
public: accessible from all classes
private: accessible from within
class
Modifiers: protected: accessible from same
method and package and subclasses
attributes default: accessible from same
package
Non-Access Modifiers:
final: cannot be
overridden/modified
Modifiers: static: Attributes and methods
method and belongs to the class, rather than
an object
attributes
abstract: Can only be used in an
abstract class, and can only be
used on methods