Sunteți pe pagina 1din 18

sohailimran@yahoo.

com

Class Diagram
Ref: Web
intro
A 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.

It consists of:

Structural features (attributes)


define what objects of the class "know"
• Represent the state of an object of the class
• Are descriptions of the structural or static features of a class

Behavioral features (operations)


define what objects of the class "can do"
• Define the way in which objects may interact
• Operations are descriptions of behavioral or dynamic features of a class

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 1


notation
A class notation consists of three parts:
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 (Methods)
• 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.
• The return type of method parameters is shown after the colon following the parameter
name.
• Operations map onto class methods in code
Function Procedure
Method A set of instructions which A set of instructions which
There are two types of methods: takes some input and takes input and
1) Function performs certain tasks and performs certain task and
2) Procedure returns a value. does NOT return a value.

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 2


relationships …...
A class may be involved in one or more relationships with other classes.

A relationship can be one of the following types:

Inheritance (or Generalization)


• Represents an "is-a" relationship.
• An abstract class name is shown in italics.
• SubClass1 and SubClass2 are specializations of Super Class.
• A solid line with a hollow arrowhead that point from the child to the parent class

Simple Association
• A structural link between two peer classes.
• There is an association between Class1 and Class2
• A solid line connecting two classes

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 3


relationships
Aggregation
• A special type of association. It represents a "part of" relationship.
• Class2 is part of Class1.
• Many instances (denoted by the *) of Class2 can be associated with Class1.
• Objects of Class1 and Class2 have separate lifetimes.
• A solid line with an unfilled diamond at the association end connected to the class of
composite

Composition
• A special type of aggregation where parts are destroyed when the whole is destroyed.
• Objects of Class2 live and die with Class1.
• Class2 cannot stand by itself.
• A solid line with a filled diamond at the association connected to the class of composite

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 4


visibility
In object-oriented design, there is a notation of visibility for attributes and operations.
UML identifies different types of visibility:
public, protected and private.
+ denotes public attributes or operations
- denotes private attributes or operations
# denotes protected attributes or operations
In the example:
• attribute1 and op1 of MyClassName are public
• attribute3 and op3 are protected.
• attribute2 and op2 are private.
Access for each of these visibility types is shown below for members of different classes.

Access Right public (+) private (-) protected (#)


Members of the same class yes yes yes
Members of derived classes yes no yes
Members of any other class yes no no

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 5


association class
Association classes are used to identify information
about an association.
The information is placed in a class attached to the
association that it describes by a dashed line.

Qualified association
Qualified associations provide the same
functionality as indexes. The notation has a bit of a
twist, so pay attention. To indicate that a customer
can look up an order using the order's ordernumber
attribute, the ordernumber attribute name is placed
in a rectangular box on the Customer end of the
association. All the other association notation
remains intact but is pushed out to the edge of the
rectangle. Also, because the qualifier is an attribute,
it may include a data type.

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 6


multiplicity
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.
Multiplicity is the active logical association when the cardinality of a class in relation to
another is being depicted.
For example, one fleet may include multiple airplanes, while one commercial airplane may
contain zero to many passengers.
The notation 0..* in the diagram means “zero to many”.

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 7


association multiplicity (cardinality)
• Constrain specifies the range of allowable objects that can be
linked with an object of other class under that association (or on
that role).
The format is, Lowerbound .. Upperbound
• Role names - may be used with association at both ends or at
one of the ends to increase clarity.

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 8


association degree (unary association)
Reflexive association
The reflexive association is used when objects in the same class can be associated.
The entire association notation remains the same, except that the association line is drawn
to and from the same class.

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 9


example

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 10


Associations

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 11


Aggregation

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 12


Generalization

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 13


types of classes

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 14


boundary class
A boundary class is used to model interaction between the system and its actors (ie.,
users and external systems).
Therefore, each physical actor/scenario pair is examined to discover boundary classes.
Note that, at the early stage of analysis and design, you are documenting the user
interface requirements, not implementing the interface.

<<boundary>>
User Interface::AddAdvertUI
User Interface::withdrawUI

startInterface( ) startInterface( )
selectAccount( ) selectClient( )
User Interface::withdrawUI
getAmount( ) selectCampaign( )

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 15


entity class
Entity classes model information and associated behavior of some phenomenon or concept
that is generally long lived.
This type of class may reflect a real-world entity such as an individual, or it may be
needed to perform tasks internal to the system.
They are typically independent of their surroundings.
Many times, they are application independent, meaning that they may be used in more than
one applications.

<<entity>>
Card Card

CardNo CardNo
PIN PIN
status status

changePIN() Card
changePIN()
checkPIN( ) checkPIN( )

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 16


control class
Control classes represent coordination, sequencing, transactions, and control of other
objects and are often used to encapsulate control related to a specific use case.
Control classes are also used to represent complex derivations and calculations, such as
business logic, that cannot be related to any specific, long-lived information stored by the
system (ie. a specific entity class). You can think of a control class as "running" or
"executing" the use case. Control classes are typically application-dependent classes. In
the early stages of the Elaboration Phase, a control class is added for each actor/use case
pair. The control class is responsible for the flow of events in the use cases.
In practice, if a control class is doing more than sequencing, then it probably is doing too
much! For example, in the Course Registration System, a student selects course offerings
and if the course offering is available, the student is added to it. Who knows how to add the
student -- the control class or the course offering?

<<control>>
Control::withdrawCtrl
Control::withdrawCtrl

withdraw( )
withdraw( )
withdrawCtrl

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 17

S-ar putea să vă placă și