You are on page 1of 30

System Analysis & Design

Class Diagram
Class Diagram

• A Class diagram is used to display some of the classes and


packages in your system

• It gives you a static picture of the pieces in the system


and
of the relationships between them

• They help the developers see and plan the structure of the
system before the code is written, helping to ensure that
the system is well designed from the beginning
Class Specifications

• Class Name

• Class Attributes

• Class Operations
It is a behavior associated with a class
Class Stereotypes
• A stereotype is a mechanism you can use to categorize your classes

•This feature helps you more thoroughly understand the responsibilities


and type of each class in your model

•There are two types of Stereotypes

1.Analysis Stereotypes used during the Analysis process which


categorizes classes based on the functions they perform

2.Language – dependent Stereotypes used during the Detailed


Design Process. Categorizes classes based on the programming
language they use.
Class Stereotypes: Analysis Stereotypes

• It is used to categorize the classes according to the functions they


perform

• There are three primary class stereotypes in UML that are used for
analysis:
• Boundary
• Entity
• Control
Class Stereotypes

Analysis Stereotypes: Boundary Classes


•Boundary classes are those classes
that lie on the boundary between your
system and the rest of the world
•These would include all of your forms,
reports, interfaces to hardware such as
printers or scanners, and interfaces to
other systems

Minimum, there must be one


boundary class for every actor–use
case interaction. If you have two
actors that both initiate the same use
case they can have the same
boundary class.
Class Stereotypes

Analysis Stereotypes: Entity Classes

•Entity classes hold information that


you may save to persistent storage

•An entity class may need to be


created for a table. Where objects
represent records and attributes
represents fields. While the table
holds a record's information
permanently, the entity class will
hold the information in memory
while the system is running
Class Stereotypes

Analysis Stereotypes: Control Classes


• Control classes are responsible for coordinating the efforts of other
classes
• Notice that the control class doesn't carry out any functionality itself,
and other classes don't send many messages to it. Instead, it sends
out a lot of messages. The control class simply delegates
responsibility to the other classes
• For this reason, control classes are sometimes called manager
classes
• Ex: SecurityManager class that is responsible for controlling events
related to security
• They are optional, but if a control class is used, there is typically one
control class per use case, which controls the sequencing of events
through the use case.
• Control classes are responsible for knowing and
carrying out the business rules of an organization.
They execute alternative flows and know what to
do in case of an error.
Package
• A package is used to group together classes that have some
commonality

• Approaches when packaging classes:


• One approach is to group the classes together by stereotype
• Another approach is to group the classes together by functionality
(Ex. Security package, math package, graphics package)
• Combination of both approaches

• Packages can be nested inside each other to further organize your


classes
Class Specifications
• Class Name - Unique Name, No spaces, Short
• Class Visibility
✔ ) Public - the class can be seen by all of the other classes in the
system
✔ Protected or private - the class can be seen in nested classes (i.e.
classes bound in aggregation or generalization relationships)
✔ Implementation - the class can be seen only by other classes in the
same package
• Class Multiplicity - The number of instances that you expect to have
of a class
• Class Attributes
• Class Operations
• Class Relationships
Class Attributes Specifications
• Data Type
• Initial Value – Not required
• Visibility
• Public - the attribute is visible to all other classes ( + )
• Private - the attribute is not visible to any other class ( - )
• Protected - the class and any of its descendants have access to the
attribute (#)
• Implementation - the attribute is public, but only to classes in the
same package
• Static Attribute - Shared by all instances of the class
• Derived Attribute - Created from other attributes , Ex. Area
is created from the height and width attributes
Class Operations
• An operation is a behavior associated with a class

• An operation has three parts:


• The Operation Name
• The Operation Parameters
• The Operation Return Type

• The parameters are arguments the operation receives as input. The


return type is the output of the operation
Class Operations Stereotypes
• There are four different types of operations to consider:
• Implementor Operations
• Implement some business functionality. They are found by examining
Interaction diagrams
• Manager Operations
• Manage the creation and destruction of objects. For example, the
constructor and destructor operations of a class fall into this category
• Access Operations
• Other classes may need to view or change the private or protected
attributes of a particular class. This can be accomplished through access
operations like Set and Get
• Helper Operations
• Operations that one class needs to carry out its responsibilities but that
other classes don't need to know about. These are the private and
protected operations of a class
Relationships

• It shows how classes communicate with one another

• A relationship is a semantic connection between classes

• It allows one class to know about the attributes,


operations, and relationships of another class
Association

• An association allows one class to know about the public


attributes and operations of another class

• Associations can be:


• Bidirectional
• Unidirectional - contains one arrowhead showing the
direction of the navigation
Association: Bidirectional

Public class Customer Public class Flight


{ {
public Flight theFlight; public Customer theCustomer;

public Customer() public Flight()


{ {
} }
} }
Association: Unidirectional

Public class Customer Public class Flight


{ {
public Customer theCustomer;
public Customer()
{ public Flight()
} {
} }
}
Association: Reflexive

•One instance of a class is related to other instances of the


same class
• Examples:
Dependencies

• A dependency relationship shows that a class references


another class

• When there is a dependency between two classes, Rose


does not add any attributes to the classes for the
relationship, which is one of the differences between an
association and a dependency

• The second difference is that dependencies are


unidirectional
Dependencies cont.

• Flight depends on Customer


• Flight won't have a Customer attribute. It therefore has to
find out about Customer some other way. There are three
ways it can know about Customer:
•Customer could be instantiated as a local variable inside
an operation of Flight
• Customer could be passed in as a parameter to some
operation inside Flight
Aggregations

• An aggregation is a relationship between a whole and its


parts

• When you generate code for an aggregation, Rose will


generate attributes to support the aggregation

SOURCE
MASTERING UML WITH
RATIONAL ROSE 2002
Aggregations: Reflexive

• A reflexive aggregation suggests that one instance of a


class is made up of one or more other instances of the
same class

• For example, when cooking, you may combine some


ingredients, which form ingredients for other things. In
other words, each ingredient can be made up of other
ingredients

SOURCE
MASTERING UML WITH
RATIONAL ROSE 2002
Generalization

• A generalization is an inheritance relationship between two


model elements
• It allows one class to inherit the public and protected
attributes and operations of another class

Superclass

Subclass
Relationships Specifications
• Setting Multiplicity
• Multiplicity indicates how many instances of one class are related to a
single instance of another class at a given point in time

• For example, Course Registration System for a university


• Courses have students and students have courses. The questions
answered by the multiplicity are
• "How many courses can a student take at one time?"
• "How many students can be enrolled in a single course at one
time?"
. Relationships Specifications cont

• Using Link Elements (Association class)


• is a place to store attributes related to an association
• For example, we may have two classes, Student and
Course. Where should the attribute Grade be placed?
• To get around this problem, we can create an association
class
Class Diagram: Checklist

1. Start with the entity classes: Classes that hold


data permanently stored for a system, for
example: tables in the system database
2. Then, draw a boundary class (Form, window or
web page) for each actor –> use case relation
in use case diagram
3. Draw a controller class for each use case (if
needed)
4. Write class attributes and operation: You can’t
create a class without any attributes or
operations
5. Draw relations & Specifiy multiplicity.
Practice
• Make a class diagram for Book and DVD ‘s store that
captures the following:
• A User has email ,password ,First and Last name , address ,zip
code ,city ,state ,country, and phone , he can make login ,
registration and logout .
• A user can be customer or seller.
• A seller has additional attribute : ID ,Item Name ,Item ID
,Discount and Category.
•A customer has: Customer ID, ship name ,ship address and no of
items , can make 1- payment
2- add card : add card information ( card number , issue
date and expiry date ) then verify card details and perform
transaction which need to add details of Transaction in database
with transaction ID , Date and amount to commit or can roll back
this transaction from database
Practice
• Make a class diagram for Book and DVD ‘s store that
captures the following:
3- add items to cart : information about item in cartdetails
(Cart No , itemID , amount ,Category) to perform add and
check out.
4- Cancel : allow customer to cancel Item order by insert his
id ,Item ID and amount ,to retrieve and update the amount in
stock.
•For Cancellation or add item to cartdetails ,the system depend
on payment system to add order from customer or refund the
money to customer ,the order contain customer ID ,customer
name ,Card no ,bill address.

SOURCE
MASTERING UML WITH
RATIONAL ROSE 2002
Class Diagram

SOURCE
MASTERING UML WITH
RATIONAL ROSE 2002
Thanks For Listening

You might also like