domain modeling yonglei tao. classes and objects in uml 2
TRANSCRIPT
Domain Modeling
Yonglei Tao
Classes and Objects in UML
2
3
SSN: String
checkin(time:float):void
name: String
checkout(time:float):void
Employee
Representing Type in UML
SaleRegister Records-current 11
association name multiplicity
-"reading direction arrow"-indicate direction of reading the association label-often excluded
Associations
4
Multiplicity
5
Associations
6
Store
Contains
Person
Airline
Em ploys
1..*
SaleRegister Captures1..*
1..*
Paym entPaid-by1
FlightAssigned-to P lane*
Assigned-to
*
Supervises
*
1
1
1
1
1 1
1
7
Inheritance
Userid: String
login(id, password)name: String
logout()
Staff Student
applyOnline()processApplication()
Rules for Inheritance A subclass is a (kind of) superclass
A superclass is more general than a subclass 100% of the superclass’s definition should
be applicable to the subclass Attributes Associations
8
Is-A Relationship
CashPayment
CreditPayment
CheckPayment
Payment
amount : MoneySalePays-for
11
9
10
Two Tests for Inheritance
Enginemodel#horse powermanufacturer
start()stop()
Car
drive()
IS-A test: every instance of a subclass is also an instance of the superclass.
Conformance test: relationships of a superclass are also relationships of subclasses.
Professornamephoneteach(...)
Visiting Professor
signContract()
Retirement Planenroll
Visiting professors cannot enroll in a retirement plan at the host university.
Car is not an engine.
Creating a Subclass Include additional features of interest
attributes associations
Include different behavior add new operations redefine superclass operations
Support software reuse (with modification)
11
Creating a Superclass Factor out common features among
subclasses common attributes, associations, and behavior code sharing
Allow potential subclasses representing variations of a similar concept provide a common interface support polymorphic processing
12
Justifying a Class Hierarchy
CreditAuthorization
Service
CheckAuthorization
Service
CheckPayment
AuthorizationService
addressnamephoneNumber
additional associations
superclass justified by common attributes and associations
StoreAuthorizes-payments-of *
Authorizes
CreditPayment
Authorizes
**
*
1 1
13
Abstract Class Represents a class that never has any
concrete instances Defines an interface for related subclasses
Every member of the class must also be a member of a subclass
CashPayment
CreditPayment
CheckPayment
Payment
amount : Money
abstract class indicated by italics
14
Abstract Classes
Payment
CashPayment CreditPayment CheckPayment
Payment
CashPayment CreditPayment CheckPayment
If a Payment instance mayexist which is not a CashPayment, CreditPayment or CheckPayment, then Payment is not an abstract conceptual class.
Payment is an abstract conceptual class. A Payment instance must conform to one of the subclasses: CashPayment, CreditPayment or CheckPayment.
(a)
(b)
abstract conceptual class
15
16
Aggregation Relationship
Carmodel#horse powermanufacturer
start()stop()
Enginemodel#horse powermanufacturer
start()stop()
part-of relationship
Composite Relationship
17
Part-Of Relationships Composite
the whole solely owns the parts the part’s lifetime is bound within the lifetime of
the whole certain properties of the whole propagate to the
parts Aggregation
logical assembly the parts can be referenced by one or more
wholes
18
Why Composition? Help determine the lifetime of a object
a create-delete dependency of the part on the whole
Help identify an object creator Provide a way of grouping
hide parts within the whole
19
Association Classes
addressnamephoneNumber
AuthorizationService
addressname
Store
merchantID
ServiceContractan association class
its attributes are related to the association
its lifetime is dependent on the association
Authorizes-payments-via
1..**
20
Association Class
21
An association class defines properties and operations for an association between two classes.
Enrollgrade: char
getGrade()setGrade(grade:char)
Student Courseenroll **
Understand Association Class
22
Alex got an “A” and Eric got a “B” for OOSE.
:Enroll
‘A’: char
getGrade()setGrade()
Alex:Student OOSE:Courseenroll
:Enroll
‘B’: char
getGrade()setGrade()
Eric:Student OOSE:Courseenroll
:Enroll
‘A’: char
getGrade()setGrade()
Alex:Student AI:Courseenroll
Alex also got an
“A” for AI.
Understand Association Class
23
Enrollgrade: char
getGrade()setGrade(grade:char)
Student Courseenroll
Student alex=new Student( ... );
Course oose=new Course ( ... );
...
Enroll e=new Enroll(alex, oose);
e.setGrade(‘A’);
class Student { ... }
class Course {...}
class Enroll { private char grade; private Student student; private Course course;
public Enroll (Student s, Course c) { student=s; course=c; } public char getGrade() {…} public void setGrade(char grade) {…}}
Implementation
24
Understand Association Class
Enrollgrade: char
getGrade()setGrade(grade:char)
Student Courseenroll
Student
Course
sid phone ... ...name
cn desctitle ... ...
Enrollsid gradecn ... ...
001 ... ... ...Alex002 ... ... ...Eric
c1 ...
... ...oosec2 ..
.... ...AI
001
A ... ...c1001
A ... ...c2002
B ... ...c1
Constraints
Stack
size : Integer { size >= 0 }
push( element )pop() : Object
three ways to show UML constraints
{ post condition: new size = old size + 1 }
{ post condition: new size = old size – 1 }
25
Steps for Domain Modeling
26
1) Collecting application domain information focus on the functional requirements also consider other requirements and documents also consider business descriptions
2) Brainstorming list important application domain concepts list their properties/attributes list their relationships
Steps for Domain Modeling (Cont.)
27
3) Classifying the domain concepts into: classes attributes / attribute values relationships
association, inheritance, aggregation
4) Visualizing the result using a UML class diagram
Brainstorming: Rules to Apply
28
Team members get together to identify and list domain specific concepts
1. nouns / noun phrases2. "X of Y" expressions (e.g., color of car)3. transitive verbs4. adjectives5. numeric6. possession expressions (has/have, possess,
etc.)7. "constituents / part of" expressions8. containment / containing expressions9. "X is a Y" expressions
Identify Important Concepts
29
“An undergraduate student or a graduate student can apply to no more than two exchange programs per semester. An application consists of an application form, two faculty recommendation letters, and a course equivalent form to be approved by an academic advisor.”…“An exchange program has program name, program type, academic department, academic subject, country, region, term of study, and language.”
Classifying Brainstorming Result
30
1. nouns/noun phrases2. "X of Y" expressions
3. transitive verbs4. adjectives 5. numeric
6. possession expressions
(has/have, possess, etc.)7. "consist of/part of"
expression8. containment / containing
expressions9. "X is a Y" expressions
class or attributes X is an attribute of Y X is part of Y X is a role in an association association relationships attribute values attribute / multiplicity values aggregation or attribute
aggregation relationships association or aggregation
inheritance
Examples
31
• exchange program• semester• undergraduate student
Domain specific nouns/noun phrases
• apply to (programs)
transitive verbs
Rule: transitive verbs association relationships
Rule: noun/noun phrase class or attribute
Because they existindependently in the application domain.
32
A car has make, model, horse power, number of seats ...
(c) car(a) make(a) model(a) horse power(a) number of seats
A customer can rent one or more cars ...
(c) customer(c) car rent
1+
Car has independent existence.Make, model, horse power, andnumber of seats do not.
noun/noun phrases numeric
possession expression
Visualizing in a Class Diagram
33
Class Exercise
34
Do the following for the vending machine (next slide).
Identify the concepts that exist in the application domain.
Classify the concepts in terms of classes attributes of classes relationships between the classes
inheritance aggregation and association
35
Class Exercise: The Vending Machine
The Vending Machine has a display, an alphanumeric keypad, a coin insertion slot, and an item dispenser. The display shows the vending items like chocolates, candies, potato chips, Coke, sprite, etc. Each type of item has a price and a label consisting of a letter A, B, C, ... and a digit 1, 2, ... A customer inserts coins through the coin slot. Each time a coin is inserted an LCD displays the total amount. The customer can press a letter and a digit to enter his selection after enough coins have been inserted. If the total amount is greater than or equals to the item selected, the vending machine dispenses the item and returns the change to the customer. A customer can change his mind and request that the coins be returned by pressing the return button.