0% found this document useful (0 votes)
15 views

Cse 470

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Cse 470

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

7/9/2021

CSE 470(5.1) – Class Diagram in UML Types of Classes


What is a Class?
 Ones found during analysis:
 A general template that we use to create
 people, places, events, and things about which
specific instances or objects in the the system will capture information
application domain  ones found in application domain
 Represents a kind of person, place, or  Ones found during design
thing about which the system will need  specific objects like windows and forms that
to capture and store information are used to build the system
 Abstractions that specify the attributes
and behaviors of a set of objects

What is an Object? Potential Classes


 External entities (e.g., other systems, devices, people) that produce or
consume information to be used by a computer-based system.
 Entities that encapsulate state and  Things (e.g., reports, displays, letters, signals) that are part of the
information domain for the problem.
behavior  Occurrences or events (e.g., a property transfer or the completion of a
series of robot movements) that occur within the context of system
 Each object has an identity operation.
 It can be referred individually  Roles (e.g., manager, engineer, salesperson) played by people who
interact with the system.
 It is distinguishable from other objects  Organizational units (e.g., division, group, team) that are relevant to an
application.
 Places (e.g., manufacturing floor or loading dock) that establish the
context of the problem and the overall function of the system.
 Structures (e.g., sensors, four-wheeled vehicles, or computers) that
define a class of objects or related classes of objects.
7/9/2021

2 Kinds of Classes during Analysis Class Names

 Concrete
The name of the class is the only required
 Class from application domain ClassName
tag in the graphical representation of a
 Example: Customer class and Employee class. It always appears in the top-most
attributes compartment.
class
 Abstract operations

 Useful abstractions
 Example: Person class

Software Design (UML)

Classes
Attributes in a Class
A class is a description of a set of
 Properties of the class about which we want to
ClassName objects that share the same attributes, capture information
operations, relationships, and semantics.
 Represents a piece of information that is relevant to
attributes the description of the class within the application
Graphically, a class is rendered as a domain
rectangle, usually including its name,
operations  Only add attributes that are primitive or atomic types
attributes, and operations in separate,
designated compartments.  Derived attribute
 attributes that are calculated or derived from other
attributes
 denoted by placing slash (/) before name

Software Design (UML)


7/9/2021

Class Attributes
Operations in a Class

 Represents the actions or functions that a


Person
An attribute is a named property of a class can perform
class that describes the object being
name : String
modeled.  Describes the actions to which the
address : Address
birthdate : Date
ssn : Id
In the class diagram, attributes appear in instances of the class will be capable of
the second compartment just below the
name-compartment. responding
 Can be classified as a constructor, query,
or update operation

Software Design (UML)

Class Attributes (Cont’d) Class Operations


Attributes are usually listed in the form:

Person attributeName : Type Person


A derived attribute is one that can be
computed from other attributes, but name : String
name : String doesn’t actually exist. For example, address : Address
address : Address a Person’s age can be computed from birthdate : Date
birthdate : Date his birth date. A derived attribute is ssn : Id
/ age : Date designated by a preceding ‘/’ as in:
ssn : Id
Operations describe the class behavior
/ age : Date
eat () and appear in the third compartment.
sleep ()
work ()
play ()

Software Design (UML) Software Design (UML)


7/9/2021

Class Operations (Cont’d)


UML Representation of Class

PhoneBook
Class Name
newEntry (n : Name, a : Address, p : PhoneNumber, d : Description)
getPhone ( n : Name, a : Address) : PhoneNumber
Attributes of Class

You can specify an operation by stating its signature: listing the name, type, and default
value of all parameters, and, in the case of functions, a return type.
Operations/methods
of Class

Software Design (UML)

Depicting Classes
Visibility
When drawing a class, you need not show attributes and operation in every diagram.
of Attributes and Operations

Person Person Person  Relatesto the level of information hiding


name : String
to be enforced
birthdate : Date
Person ssn : Id

name Person eat()


address sleep()
birthdate work()
eat () play()
play ()

Software Design (UML)


7/9/2021

Visibility Relationships among Classes


of Attributes and Operations
 Represents a connection between multiple classes or
Visibility Symbol Accessible To a class and itself
Public + All objects within your system.  2 basic categories:
 association relationships
Protected # Instances of the implementing class and its subclasses.
 Aggregation
 Composition
 generalization relationships
Private - Instances of the implementing class.

Visibility (Cont’d)
Association Relationship
A bidirectional semantic connection
Person between classes
Attributes can be:  Type:
+ name : String + public
# address : Address
# protected  name of relationship
# birthdate : Date
/ age : Date - private  role that classes play in the relationship
- ssn : Id / derived

+ eat ()
+ sleep ()

Software Design (UML)


7/9/2021

Association Relationships (Cont’d)


Association Relationship
We can indicate the multiplicity of an association by adding
 Name of relationship type shown by: multiplicity adornments to the line denoting the association.
 drawing line between classes The example indicates that a Student has one or more
 labeling with the name of the relationship Instructors:
 indicating with a small solid triangle beside the
name of the relationship the direction of the Student
1..*
Instructor

association

Patient Provides Medical History

Software Design (UML)

Association Relationships Association Relationships (Cont’d)

If two classes in a model need to communicate with each other,


there must be link between them.
The example indicates that every Instructor has one or more
An association denotes that link. Students:

Student Instructor Student Instructor


1..*

Software Design (UML) Software Design (UML)


7/9/2021

Association Relationship Aggregation Relationship

 Aggregations are denoted by a hollow-


 Role type shown by:
 drawing line between classes diamond adornment on the association.
 indicating with a plus sign before the role
name
Patient
Engine
+ primary insurance Car
carrier Transmission

Aggregation Relationship Composition Relationship


 Specialized form of association in which a  A composition indicates a strong ownership and
coincident lifetime of parts by the whole (i.e., they live
whole is related to its part(s) and die as a whole). Compositions are denoted by a
 Represented by a-part-of relationship filled-diamond adornment on the association
 Specifies a whole-part relationship
between an aggregate (a whole) and a Scrollbar
constituent part, where the part can exist
independently from the aggregate. Window Titlebar

Menu
7/9/2021

Generalization Relationship Generalization Relationships (Cont’d)


UML permits a class to inherit from multiple superclasses, although some
programming languages (e.g., Java) do not permit multiple inheritance.
 Enables the analyst to create classes that
inherit attributes and operations of other
classes Student Employee
 Represented by a-kind-of relationship

TeachingAssistant

Software Design (UML)

Generalization Relationships
Generalization Relationship

Person Person
A generalization connects a subclass
to its superclass. It denotes an
inheritance of attributes and behavior
from the superclass to the subclass and Employee Customer
indicates a specialization in the subclass
of the more general superclass.
Student

Manager Engineer

Software Design (UML)


7/9/2021

Generalization Relationship Multiplicity

Employee  Denotes
the minimum number..
hireDate
maximum number of instances
Exactly one 1
receivePay Zero or more 0..* or 0..m
performWork
One or more 1..* or 1..m
Zero or one 0..1
Manager Engineer Specified range 2..4
department certifications Multiple, disjoint ranges 1..3, 5
bonus
hireEmployee analyze
promoteEmployee design

Multiplicity Guidelines (5.2)


 Documents how many instances of a for Analyzing Requirements / Use Cases
class can be associated with one instance A common or improper noun implies a
of another class class of objects
 A proper noun implies an instance of a
class
Patient
1 provides 0..1 Medical History  A collective noun implies a class of
objects made up of groups of instances of
another class
7/9/2021

Guidelines
for Analyzing Requirements / Use Cases (2) Class Diagram

 An adjective implies an attribute of an  Ensure that the classes are both necessary
object and sufficient to solve the underlying
 A doing verb implies an operation
problem
 no missing attributes or methods in each class
 A being verb implies a relationship
 no extra or unused attributes or methods in
between an object and its class each class
 A having verb implies an aggregation or  no missing or extra classes
association relationship

Guidelines Discarding Unnecessary and Incorrect


for Analyzing Requirements / Use Cases (3) Classes

A transitive verb implies an operation  Redundant Classes: Some potential classes


 An intransitive verb implies an exception differ only in name.
 A predicate or descriptive verb phrase  Irrelevant Classes: Classes that have

implies an operation nothing to do with the system. Example:


 An adverb implies an attribute of a
computer connection
relationship or an operation  Vague Classes: Classes whose meaning is
not clear at all. Examples: system and
software
7/9/2021

Discarding Unnecessary and Incorrect


Classes Example of a Class Diagram
 Attributes: Some nouns in the list above are likely to Video Rental System
be modeled as attributes rather as classes. Examples:
author, title visibility multiplicity class name
 Operations: Some nouns are likely to be operations
rather than classes. Example: book search. Customer Video
1..* 1..*
 Roles: Some nouns are roles of objects involved in -CID: int -cassetteID : int
associations rather than classes. -name: String rents -cassetteVolumeNo: int

 Implementation Constructs: Anything that is not part +authenticateCustomer ()


+rentMovie()

of the real-world problem.


attributes relationship methods

Types of Classes Class diagram example 1

 Ones found during analysis: Multiplicity

people, places, events, and things about which


Customer
1 Simple
 Class Aggregation

the system will capture information


Rental Invoice
 ones found in application domain
Abstract
Class

 Ones found during design Rental Item 1..*


1 0..1
 specific objects like windows and forms that Composition Simple
Generalization
are used to build the system Association

Checkout Screen
DVD Movie VHS Movie Video Game

44
7/9/2021

Class diagram example 2

45

Class Diagram Example 3

Slide 46

You might also like