System Analysis & Design System Analysis & Design
System Analysis & Design System Analysis & Design
COMP 211
Generalization
inheritance
COMP 211
OBJECT-ORIENTED MODELING
[2.3]
Why models?
to abstract reality
filter out non-essential details
to allow us to focus on the big picture to promote understanding, cleaner design, maintainable systems
Why objects?
to reflect reality more accurately to reduce the semantic gap between reality and a model
specification
consider interfaces of objects (but no internal aspects)
implementation
consider all details of objects (external and internal)
COMP 211
ABSTRACTION
[2.3.2]
mental process of selecting some characteristics and properties and excluding others that are not relevant
abstraction is always for some purpose many different abstractions of the same thing are possible all abstractions are incomplete descriptions of reality
COMP 211
QUESTION?
If you had to draw a map of the area around HKUST to explain to someone someone how how to get to get to HKUST to HKUST from from Choi Choi Hung, Hung, what what is the is the one most one important most important thing you thing would you include? would include?
1) roads. 2) land topology (e.g., contours showing elevation above sea level. 3) historical sites to see (e.g., the HKUST beach). 4) the types and places of vegetation (i.e., trees and other types of plants). 5) location of hiking trails. 6) bus routes.
COMP 211
QUESTION?
If you had to draw a map of the area around HKUST to explain to someone someone how how high high the the Academic Academic Building Building is above is above seasea level, level, what is the what one ismost the one important most important thing youthing would you include? would include?
1) roads. 2) land topology (e.g., contours showing elevation above sea level. 3) historical sites to see (e.g., the HKUST beach). 4) the types and places of vegetation (i.e., trees and other types of plants). 5) location of hiking trails. 6) bus routes.
COMP 211
TYPES OF ABSTRACTIONS
[2.3.2]
IS_MEMBER_OF relationship
Word
PowerPoint
. . .
Access
Oracle
. . .
Sybase
COMP 211
airplane
IS_PART_OF relationship
wing
landing gear
. . .
fuselage
ignore differences among the parts and concentrate on the fact that they form the whole
COMP 211
student
IS_A relationship
secondary
undergrad
. . .
postgrad
subclass/subtype
classification applied to individual instances of objects generalization applied to sets of objects (classes)
COMP 211 OO MODELING WITH UML10
undergrad
classification
Sam
Tina
. . .
John
aggregation
name
student id
. . .
COMP 211
QUESTION?
Consider the relationship between files and directories in a computer system. Which type(s) of abstraction models this relationship?
1) classification only 2) aggregation only 3) generalization only 4) classification and aggregation 5) aggregation and generalization 6) classification and generalization 7) classification, aggregation and generalization directory 8) none of the above
file
COMP 211
OBJECT
[2.3.4; 2.4.2]
a concept, abstraction or thing with crisp boundaries and meaning which plays a role with respect to a request for an operation
COMP 211
state
Amount (money value) Balance Method (code)
Balance Balance
Deposit Method (code)
Deposit Deposit
Withdraw Method (code)
behavior
Withdraw Withdraw
Pay-interest Method (code)
Pay interest
COMP 211 OO MODELING WITH UML14
OBJECT ENCAPSULATION
a kind of abstraction that enforces a (clean) separation between the external interface and the internal implementation of an object
object 1 user
request response
object 2 interface
request response
interface
hides unnecessary details of implementation (information hiding) and ensures modularity an object has a visible (public) interface and a hidden (private) implementation
OO MODELING WITH UML16
COMP 211
OBJECT PROPERTIES
each object has a unique, immutable identity independent of its current state or behavior OID
objects communicate by responding to stimuli that invoke their operations message passing
Deposit(...)
Teller Alice
COMP 211
(OBJECT) CLASS
state behavior
[2.3.4; 2.4.2]
Why classes? convenient way of describing a collection of objects specify what values are acceptable in a given context How are classes and modules related? classes can be thought of as loosely coupled, highly cohesive modules
COMP 211 OO MODELING WITH UML18
QUESTION?
Which apply type classification of abstraction abstraction relates objects to objects and to classes? form classes
1) classification only 2) aggregation only 3) generalization only 4) classification and aggregation 5) aggregation and generalization 6) classification and generalization
IS_MEMBER_OF relationship
7) classification, aggregation and generalization 8) none of the above (this is not a type of abstraction)
COMP 211
CLASS ATTRIBUTE
a description of data values held by objects in a class
visibility: public (+), protected (#), private (-) initial value (optional) multiplicity (optionaldefault is exactly 1) changeability: frozen, addOnly, no constraint (default)
COMP 211
<<sterotype>> visibility name [multiplicity]: type-expression = initialvalue {property-string} property-string -> a comma separated list of properties or constraints
Examples
+ size: Area = (100,000) {frozen} name: string telephone[0..2]: string telephone[1, 3..4]: string - salary: Money {>0, <1,000,000}
COMP 211
Question?
apply aggregation abstraction Which type of abstraction relates
1) classification only 2) aggregation only 3) generalization only Course 4) classification and aggregation 5) aggregation and generalizationIS_PART_OF 6) classification and generalization relationship 7) classification, aggregation and generalization course# 8) none of the above (this is not a type of abstraction) name instructor prerequisite
COMP 211
CLASS OPERATION
a function or transformation that may be applied to or by objects in a class
invoked by a message sent to an object operation signature: name of operation (selector), number and types of the arguments, and the type of the result value visibility: public (+), protected (#), private (-) side effects: if the execution of an operation changes the state of an object (query operation no side effects)
COMP 211
- multiple calls to an object may occur simultaneously, but only one is allowed to at a time; other calls are blocked multiple calls may occur simultaneously to object and all execute concurrently
concurrent -
COMP 211
CLASS METHOD
the implementation of an operation for a class
operation print
ASCII file print method digitized file print method
dynamic binding choosing the method to execute for an operation based on the objects class How does a requesting object know whether the returned value is the result of accessing an attribute value or of a calculation performed by a method?
COMP 211
CLASS UML GRAPHICAL NOTATION Class name attribute compartment operation compartment extra compartment
derived attribute Visibility
+ public - private # protected
Company +name: string +address: string +stock price: money +profit: money /pe ratio: decimal #hire #fire -pay-dividend
COMP 211
GENERALIZATION
[2.4.2]
Vehicle
vehicle-type
subclass
Van
superclass
Car
car-size
Truck
discriminator
Compact
subclass
Midsize
Full-size specialization
discriminator: an attribute of enumeration type that indicates which property of a class is being abstracted by a generalization
COMP 211 OO MODELING WITH UML27
GENERALIZATION INHERITANCE
the assumption of properties by a subclass from its superclasses
extract similarities (common attributes and operations), put them in a superclass and inherit them to subclass(es)
reduces redundancy promotes reusability
COMP 211
Account
account-number amount balance deposit withdraw
Checking
service-charge withdraw
Savings
interest-rate withdraw
Checking Savings
service-charge interest-rate withdraw
COMP 211 OO MODELING WITH UML29
id
Student
Employee
id
id
id
id
id
Undergrad
Postgrad
Staff
Faculty
? id
COMP 211
TA
id ?
OO MODELING WITH UML30
Student
id
Employee
id
id
id
id
id
Undergrad
Postgrad
Staff
Faculty
? id
TA
id ?
COMP 211
Vehicle
weight
Land vehicle
size
displacement
Water vehicle
size
Car
Amphibious vehicle
name conflict
Boat
COMP 211
used as a container for definitions, but no instances of the class are of interest Account
Checking
Savings
GENERALIZATION CONSTRAINTS
overlapping - a superclass object can be a member of more than one Player subclass Player
Soccer Female
Tennis
{overlapping}
Tennis
Soccer
Person
Male
Female
OO MODELING WITH UML34
COMP 211
incomplete - some superclass object is not a member of any subclass Tree Elm Oak Tree Birch
COMP 211
Postgrad
{complete}
Undergrad
Postgrad
{incomplete}
Oak
Elm
Birch
OO MODELING WITH UML35
Player
Soccer PG
Tennis
{overlapping, incomplete}
Soccer
Course
UG
UG
COMP 211
PG
OO MODELING WITH UML36
Postgrad
{disjoint, complete}
Undergrad
Postgrad
{disjoint, incomplete}
Oak
Elm
Birch
QUESTION?
Payment
{disjoint, complete}
Cash
Credit-card
Debit-card
COMP 211
QUESTION?
Customer
{overlapping, complete}
WWW
In-store
COMP 211
LINK
[2.4.2]
Teaches
ASSOCIATION
[2.4.2]
Person
Works-for
Course
class diagram
Person
Organization associations
Organization
COMP 211
ASSOCIATION (contd)
Person
Works-for Attended Works-for
University
Fred
U Toronto
Person
Married-to Manages
COMP 211
QUESTION?
Which apply type aggregation classification of abstraction abstraction abstraction relates to links toclasses links and to associations? to form form associations associations
3) generalization only 4) classification and aggregation Person 5) aggregation and generalization University 6) classification and generalization 7)Person classification, aggregationUniversity and generalization 8) none of the above (this is not a type of abstraction)
COMP 211
ASSOCIATION DEGREE
unary
relates a class to itself
Person Manages
binary
Person
Teaches
Course
ternary
Project
Language
Person
COMP 211
Customer
Account
Customer
Has
Account
Is-with
Bank
COMP 211
Project
Language
Mary
John
CAD
C Cobol
Accounting
COMP 211
Mary
John
CAD
C Cobol
Accounting
COMP 211
Accounting
CAD
Mary
John
Cobol C
COMP 211
cannot tell that Mary uses only Cobol on Accounting and John uses only C on Accounting
OO MODELING WITH UML48
C Cobol
CAD
Accounting
John Mary
COMP 211
cannot tell that Mary uses only C on CAD and not on Accounting
OO MODELING WITH UML49
ASSOCIATION MULTIPLICITY
specifies restrictions on the number of objects in each class that may be related to objects in another class
1..1
Instructor
Teaches
0..1
Course
assume each course can be taught by one and only one instructor
a real-world constraint!
COMP 211 OO MODELING WITH UML50
c..d
C2 max-card(C1,A) min-card(C1,A)
COMP 211
Capital-of
1..1 1
City
Capital-of
COMP 211
Assigned-to
1..1 1
Department
Assigned-to
COMP 211
Supplies
Part
Supplies
Lansing
COMP 211
QUESTION?
? 10..45
Enrolled-in
Student
? 1..5
Course
A student must enroll in at least one course and can enroll in at most five courses
A course must have at least ten students enrolled in it and cannot have more than forty-five students enrolled in it.
COMP 211
given a ternary association among classes (A, B, C), the multiplicity of the C end states how many C objects may appear in association with a particular pair of (A, B) objects
Registration
Course
0..1
Professor
Student
0 or 1 professor for each (course, student) a student will not take the same course from more than one professor, but a student may take more than one course from for each (student, professor) many courses one professor and a professor may teach more than one course for each (course, professor) many students
OO MODELING WITH UML57
COMP 211
QUESTION?
Meets
Course
0..3
Day
0..1
Classroom
for each (course, classroom) for each (course, day) for each (classroom, day)
COMP 211
AGGREGATION/COMPOSITION ASSOCIATION
[2.4.2]
a special type of association in which there is a part-of relationship between one class and another class
Has
Computer
Disk
a component may exist independent of the aggregate object of which it is a part aggregation
Course
Has
Course-offering
a component may not exist independent of the aggregate object of which it is a part composition
OO MODELING WITH UML59
COMP 211
AGGREGATION/COMPOSITION (contd)
sometimes it is not clear whether the parts should be related with or Chassis Car Engine
Transmission
Doors
Frame
Which aggregation association to use is a matter of how one interprets reality and/or the requirements of the application
OO MODELING WITH UML60
COMP 211
Would you use the phrase part of to describe the association or name it Has? Are operations on the whole automatically applied to the part(s) composition? Are some attribute values propagated from the whole to all or some of the parts? Is there an intrinsic asymmetry to the association where one object class is subordinate to the other(s)?
[2.4.2]
Person
Company
COMP 211
Person
Worker
Manages
John Sarah
Boss
COMP 211
ASSOCIATION QUALIFIED
qualifier an attribute or list of attributes whose values serve to partition the set of objects associated with an object across an association Order
1
product
* 0..1
Order line
Team
position
1..2 10
Player
an object in the source class together with a value of the qualifier uniquely select a partition in the set of target class objects use when we want to show the basis on which we partition the target set (for implementation purposes)
OO MODELING WITH UML64
COMP 211
ASSOCIATION CONSTRAINTS
ordering Country
1
Has
{ordered} *
President
subset
*
Member-of
{subset}
* *
Person
Committee
Chair-of
general C1
a..b
A
{Boolean expression}
c..d
C2
COMP 211
[2.4.2]
Enrolled-in
Course
Enrolled-in
grade
Course
COMP 332
C A B
Joe
B+ ACOMP 303
COMP 201
COMP 211
salary
?
Company
name address
Person
name hkid address
Works-for
COMP 211
UML RELATIONSHIPS
association describes links among object instances (only relationship that relates object instances)
generalization
relates a more general class (superclass) to a more specific kind of the general class (subclass)
dependency
flow usage realization
COMP 211
STEREOTYPE
a new class of modeling element, which is a subclass of an existing modeling element
Example:
we can define different kinds of classes that are useful for modeling
<<control>> <<boundary>> <<entity>>
PenTracker
OrderForm
BankAccount
PenTracker
OrderForm
BankAccount
COMP 211
[2.4.2]
1..*
Item
description picture cost
Payable
1 * *
Invoice
amount date due date
buyer
1
Account
VIP
expiry date
COMP 211 OO MODELING WITH UML70
Client
EventHandler
- currentEventId: integer - source: string handleRequest(): void
GUIEventHandler
COMP 211
UML Object Model Class name attribute compartment operation compartment Student
{complete, disjoint}
Undergrad
Grad
Student
10..45
Enrolled-in
1..5
Course
Course
Course-offering
COMP 211
EXAMPLE
Construct a class diagram for the classes listed below. Use association, aggregation and generalization relationships as necessary. Show multiplicity for all relationships and role names where necessary.
file disk
COMP 211
EXAMPLE
The classes shown have attributes that are really pointers (OIDs) to other classes and which should be replaced with relationships. In the current design, a person may have up to three companies as employers. Each person has an ID. A car is assigned an ID. Persons, companies, or banks may own cars. Car owner ID is the ID of the person, company, or bank who owns the car. A car loan given by a bank may be involved in the purchase of a car. Prepare a class diagram in which the pointers are replaced with relationships. Use associations, aggregations, generalizations and association classes as necessary. Show the most likely multiplicities for all associations and the final attributes for each class. Note: Your final class diagram should contain no IDs.
COMP 211
EXAMPLE
Car loan vehicle ID customer type customer ID account number bank ID interest rate current balance
COMP 211