You are on page 1of 24

CST205 OBJECT ORIENTED

PROGRAMMING USING JAVA

MODULE 1-CLASS DIAGRAM


Class Diagram
 Class diagram in the UML is a type of static structure diagram to
represent the design of the software system in terms of classes
and their relationships..
 It shows the structure of a system at the level of classes and
interfaces, along with their attributes, operations, and the
relationships among objects.
 There are several software tools available to create UML Class
diagrams. Rational rose, StarUML and Lucidchart are some of the
popular tools.
 Some common types of class diagrams are:
1. Domain Model Diagram - representation of real-world
conceptual classes (contains only attributes), not of software
components, to understand the project domain.
2. Implementation Classes Diagram - representation of the
structure of software components, describes classes, interfaces,
associations, usage, realization.
UML notation for Class
 A class notation consists of three parts:
1. Class Name (mandatory): The name of the class appears in the first
partition.
2. Class Attributes[optional]: An attribute is a named property of a
class that describes the object being modelled
 Attributes are shown in the second partition.
 The attribute type is shown after the colon.
 Derived attribute is designated by a preceding ‘/’
 Attributes map onto member variables (data members) in code.

3. Class Operations(Methods)[optional]:
 Operations are shown in the third partition. They are services the
class provides.
 The return type of a method is shown after the colon at the end of
the method signature. Operations map onto class methods in code
 The datatype of method parameters are shown after the colon
following the parameter name
Member visibility
 Visibility defines whether attributes and operations of
specific classes can be seen and used by other classes
 UML has 4 types of visibility and it is represented by
prefixing a literal( +, -, #, ~)
Member scope
 The UML specifies two types of scope for members:
instance and classifier.
 Classifier members are commonly recognized as
“static” in many programming languages. The scope is
the class itself.
 All the instances share the classifier scoped members.
 To indicate a classifier scope for a member, its name
must be underlined. Otherwise, instance scope is
assumed by default.
 Instance members are scoped to a specific instance.
Each instantiated object of the class has its own copy of
the instance members
Parameter Directionality
 Each parameter in an operation (method) may be
denoted as in,out ,or inout which specifies its direction
with respect to the caller
 This directionality is shown before the parameter name.
Relationships between classes
 Relationships in class diagrams include different types
of logical connections.
Relationships between classes
1. Dependency
A dependency means the relation between two
or more classes in which a change in one may
force changes in the other.
 Dependency indicates that one class depends
on another.
 A dashed line with an open arrow
2. Aggregation
 A special type of association to represent a "has a"
relationship eg. Team has 9 Players
 A solid line with an unfilled diamond at the association end
connected to the class of composite.It models a whole-part
relationship between aggregate and its parts
 Eg: class college is made up of one or more student.
 In aggregation the contained classes are never totally
dependent on the lifecycle of the container. Here the college
class will remain even if the student is not available
3. Composition
A special type of aggregation where parts are destroyed
when the whole is destroyed.
 A solid line with a filled diamond at the association
connected to the class of composite
 It denotes strong ownership between two classes when
one class is a part of another class
4. Generalization (Inheritance)
 A generalization helps to connect a subclass to its superclass. A
sub-class is inherited from its superclass.
 A solid line with a hollow arrowhead that point from the child to
the parent class
 Class diagram allows inheriting from multiple superclass
5. Realization (Implements)
 Realization relationship is a relationship between two
model elements, in which one model element (the
client) realizes (implements or executes) the behaviour
that the other model element (the supplier) specifies.
6. Association
 Represents static relationships between two classes.
 Shows that instances of classes could be either linked to each
other or combined logically or physically.
 Represented by a solid line (with or without open arrow)
connecting two classes
 This kind of relationship represents static relationship
classes A and B
 Eg: a person lives at a location
 It should be named to indicate the role played by the
class attached at the end of the association path
ATM MACHINE CLASS DIAGRAM
EXAMPLE

You might also like