Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Uml c4-bieudolop
1. CHƯƠNG IV
Biểu đồ lớp
Phân tích Thiết kế HĐT
UML
1
2. Nội dung
1. Phương pháp hướng đối tượng
1. Phương há hướ
1 Phươ pháp hướng đối tượng?
tượ ?
2. Xác định đối tượng
2. Biểu
2 Biể đồ lớp
lớ
1. Biểu đồ lớp?
2. Biểu diễ
2 Biể diễn quan hệ ( l ti
(relationship)
hi )
2
3. 1. Phương pháp hướng đối tượng
Phân tích Thiết kế HĐT
Structured
amount
Account amount message
message withdraw
ithd
aNo balance withdrawal
Account
ER DFD with Data Store Structure Chart
OO approach MyAccount
Objects aNo= 101 withdraw(X)
( )
:MyAccount
balance=500
balance( )
withdraw( )
---
3
4. Nguyên lý cơ bản
Object Orientation
Obj t O i t ti
tion
on
ty
Hierarchy
y
bstractio
odularit
Encapsulat
Mo
Ab
4
5. Những thuộc tính cơ bản
Phân tích Thiết kế HĐT
Data and operations
Encapsulation
Classes and objects
Generalisation/Specialisation
+ Polymorfism
y
= Object-orientation (OO)
6. Sự trừu tượng (Abstraction)?
Salesperson
Not saying Which
salesperson –
j
just a
salesperson in
general!!!
Product
Customer
Manages Complexity
M C l it
6
7. Tính đóng gói (Encapsulation)?
Phân tích Thiết kế HĐT
Che dấu việc thực thi (tính mềm dẻo)
Clients depend on interface
How does an object encapsulate?
What does it encapsulate?
Improves R ili
I Resiliency
7
8. Tính đóng gói
Phân tích Thiết kế HĐT
easy to use (dễ dùng)
-3 advantages ? ) more reliable (tin cậy)
less coupling (liên kết thấp)
Account Name of Class
aNo Data balance(?)
balance (usually hidden) My Account::
balance( ) withdraw(X) aNo=101
Methods balance=300
withdraw( ) (usually
--- interface)
9. Giao tiếp qua interface (giao diện)
Phân tích Thiết kế HĐT
Manufacturer B
Manufacturer A Manufacturer C
Polymorfism
9
10. Tính phân đoạn (Modularity)?
Phân tích Thiết kế HĐT
Order
Entry
Order Processing
System Order
Fulfilment (thực hiện)
Billing
Manages Complexity
10
11. Hệ thống cấp bậc (Hierarchy)?
Phân tích Thiết kế HĐT
Asset
Increasing
abstraction
BankAccount Security RealEstate
Savings Checking Stock Bond
Decreasing
Những thành phần cùng mức phân cấp sẽ
abstraction
b t ti
cùng mức trừu tượng
11
12. Xác định đối tượng
Phân tích Thiết kế HĐT
Object
Class
Cl
Attribute
Operation
Relationships
Interface (Polymorphism)
12
13. Đối tượng (Object)
Phân tích Thiết kế HĐT
Rumbaugh et al. (1991)
We d fi
W define an object as a concept, abstraction,
bj t t b t ti
or thing with crisp boundaries and meaning for
the problem at hand. Objects serve two
purposes:
they promote understanding of the real world
they provide a practical basis for computer
implementation.
Not every modeller may agree on the choice, meaning, and
sometimes the need for tangible and intangible objects.
14. Đối tượng ?
Phân tích Thiết kế HĐT
Thực thể vật lý
Thực thể khái niệm
ể
Thực thể phần mềm…
Chemical
Process
Truck
Linked List
14
15. Đối tượng
Phân tích Thiết kế HĐT
Một đối tượng là một khái niệm, một sự trừu
tượng hay
tượ h là một sự vật (thi ) có ranh giới rõ
ột ự ật (thing) ó h iới õ
ràng và có ý nghĩa cho một ứng dụng
Một đối tượng cóó
Trạng thái (State)
Hành vi (Behavior)
Định danh (Identity)
15
16. Object
Phân tích Thiết kế HĐT
Relational
databases
Data
Sven Lund
modelling
Olle Macho
Feelings
Project
Anna Lind management
Ulla Rask
Erik Gadd
A thing can
be either
Students
concrete or
abstract. Courses
An object is an
instance of a thing
thing. An object is something, we
something
want to hold information
about.
17. Biểu diễn đối tượng
Phân tích Thiết kế HĐT
: Professor
a + b = 10
ProfessorClark
Class Name Only
Professor Clark
ProfessorClark :
Professor Object Name Only
Class and Object Name
17
18. Ví dụ một đối tượng
Phân tích Thiết kế HĐT
Coffee
machine Class
Cl
Coffee machine
• Bl k coffee
Black ff Attributes
• Coffee with
sugar ...
• Coffee with
cream Operations
• Coffee with
cream and sugar Black coffee
Coffee with sugar
g
Coffee with cream
Coffee with cream
and sugar
...
19. Study case: Xác định đối tượng (1)
Phân tích Thiết kế HĐT
We have a family with a father (John), a mother (Jane), two sons (Peter and
Paul), and two daughters (Elizabeth and Mary). John is a businessman and
works for Ericsson Radio System. Jane is a lecturer and works at Stockholm
System
University. All the children are students at Stockholm University. Peter
studies Polish, Paul studies statistics, Elizabeth studies computer science
and Mary studies Russian. The family has a dog called Jaruzelski and Peter
y y g
has a friend Krzysztof from Poland.
Recently, Ericsson have realised that Poland is going to be a prosperous
market for their products. Hence, they ordered John to study Polish. They
believe that the knowledge of Polish will substantially improve business
b li th t th k l d f P li h ill b t ti ll i b i
relationships between Ericsson and some Polish companies. Hence, John
has just started learning Polish at ABF.
Two days ago, John was assigned a task to write a letter to one Polish
company called “Polska Telekomunikacja”. John realised that he cannot
write this letter, not yet. His Polish is not good enough. Therefore, he asked
his son Peter whether he might write this letter. John would write the letter in
Swedish, d P t
S di h and Peter would translate it to Polish.
ld t l t t P li h
20. Study case: Xác định đối tượng (2)
Phân tích Thiết kế HĐT
He would pay 1000 SEK to Peter for this help. Peter agrees and
says that he will translate this letter. The translation should be
finished by this evening.
In the afternoon, Peter comes from his lectures and is exhausted
from a long day at university. When reading John’s letter, he
realises that his Polish is not good enough. He must look up too
many words in a Swedish-Polish dictionary. This would require
more than 6 hours. He decides to ask Krzysztof to do the
translation for him.
Krzysztof agrees to do the translation. He does it within 30
minutes. Krzysztof does it as a favour. He refuses to accept
money from Peter. Krzysztof pleases himself with “Dziekuje” in
Polish, hi h
P li h which means “Thank you”.
“Th k ”
Later that evening, John comes home, gets Peter’s translation
and pays him money. He also reads the letter, and things that
Peter has done a wonderful j b Hence, he complements Peter on
P t h d d f l job. H h l t P t
his professionalism.
21. Xác định đối tượng
Phân tích Thiết kế HĐT
Object
Class
Cl
Attribute
Operation
Relationships
Interface (Polymorphism)
21
22. Lớp (Class)?
Phân tích Thiết kế HĐT
Một lớp là mô tả của một nhóm đối tượng với
thuộc tính (
th ộ tí h (properties - attributes) chung, hà h vi
ti tt ib t ) h hành i
(behavior - operations), quan hệ (relationships),
và ngữ nghĩa (semantics)
Một đối tượng là một thể hiện (instance) của một
lớp
Một lớp là một sự trừu tượng trong đó nó:
Nhấn mạnh đến những đặc tính chung
Bỏ qua những đặc tính riêng biệt
OO Principle: Abstraction
22
23. Lớp khóa học
Class
Course
Properties Behavior
Name Add a student
Location Delete a student
a + b = 10
Days offered Get course roster
Credit hours Determine if it is full
Start time
End time
23
24. Biểu diễn lớp
Phân tích Thiết kế HĐT
a + b = 10
Professor
Professor Clark
Class Name Professor
name
Attributes (tc) empID
Operations (hv) create( )
save( )
delete( )
change( )
24
25. Study case: Xác định lớp (1)
Phân tích Thiết kế HĐT
We need write an application supporting us in managing
the information about university operation Right now, at
operation. now
Stockholm University we have a substantial amount of
students - 35 000 students. To manually manage all
information abo t st dents simpl impossible Hence
info mation about students is simply impossible. Hence, SU
needs some automated support. In addition to this, we need
handle information on courses and lecturers giving these
courses.
Recently, SU has taken over the library and book shops.
They want to provide better service to their students and
students,
they want to better integrate the management of course
literature with all other courses given at SU. Hence, they
wish to automate the book management as well.
26. Study case: Xác định lớp (2)
Phân tích Thiết kế HĐT
This gives them better insight into the education on the
course level and provides a solid basis for evaluating the
level,
courses and a basis for establishing the incremental
educational programme. The knowledge of which books are
utilised on which course helps them identify the overlapping
in the educational material.
To be able to provide high quality education SU must have
education,
highly competent lecturers. SU wishes to store information
about their lecturers and their state of competence and its
development.
d l t
27. SC: Biểu đồ lớp
Phân tích Thiết kế HĐT
Student Lecturer Book shop
Competence
Course
Evaluation
Course Evaluation
Book
B k
Library
Course Competence
Overlapping
O l i
University Do we need a class called University?
28. Xác định đối tượng
Phân tích Thiết kế HĐT
Object
Class
Cl
Attribute
Operation
Relationships
Interface (Polymorphism)
28
29. Thuộc tính (Attribute) ?
Object
Class
Attribute Attribute Value
:CourseOffering
number = 101
b
startTime = 900
CourseOffering endTime = 1100
number
startTime
endTime :CourseOffering
number = 104
startTime = 1300
endTime = 1500
29
30. Thuộc tính và trạng thái
Phân tích Thiết kế HĐT
Course
course_number: String
course_name:
course name: String
no_of_students: Integer
teacher_name: String
State 1 State 2 State 3
Polish: Course Polish: Course Polish: Course
PPP234 PPP234 PPP234
Polish Polish Polish
12 34 34
Adamski Szczyperski
When an attribute value changes, the object itself
changes states.
31. Tìm thuộc tính
Phân tích Thiết kế HĐT
Đối tượng được mô tả tổn q như thế nào ?
ợ g ợ quát
Phần nào trong mô tả tổng quát có thể áp dụng cho
lãnh vực quan tâm ?
Mô tả tối giản cần thiết cho ứng dụng sẽ như thế
nào ?
32. Che dấu thông tin
Phân tích Thiết kế HĐT
Class: Person
name() Class: Student
address() pnr: Integer age()
Change_address David Parnas
name: String (Tjädervägen ….) – the founder
birth_date: Integer of OO
address: String changes
data
change_address(new_address)
change address(new address)
requires
service Class: Student
Only the object’s own code Change_address
(Tjädervägen ….)
may read and change its own
data l
d t values.
33. Tính khả kiến
Phân tích Thiết kế HĐT
In UML, the visibility is normally
Person
designated by a plus or minus
symbol:
- pnr: Integer + for public visibility
- name: String - for private visibility
- birth_date: Integer
- address: Stringg
+ name()
+ age()
- count age()
+ address()
dd () Not only the attributes are hidden
hidden.
+ change_address(new_address) Operations may be hidden as well.
34. Case Study: xác định thuộc tính (1)
Phân tích Thiết kế HĐT
At SU, many students come from all over the world. So, SU does not
only need store information about the student names, addresses, but also
information about their nationalities, translations of their degrees and so
on. Due to the fact that it is impossible to uniquely identify students by
name, SU needs some kind of a unique identifier for each student. The
automatic Object ID supplied by the system is not enough. One needs a
more mnemotechnic identifier to be managed by people. Hence, one
people Hence
decides to use Swedish personal number as an identifier.
Some courses require that the students undergo special IQ - tests.
These courses are often very expensive. Hence, only the best students
may attend them. It is not enough that they have good high school
grades. They must also undergo an especially designed IQ-test. The
results of this test are stored in the SU application.
Recent studies have shown that there are too many old students at SU. SU
The average age right now is 45. Hence, social democrats started a
campaign to make younger people get more interested in university
studies. To find out whether the campaign g
p g gives some results, the
,
Swedish politicians require that SU regularly compiles the average age of
the students.
35. Case Study: xác định thuộc tính (2)
Phân tích Thiết kế HĐT
Concerning the lecturers, SU needs to store the basic personal data
such as name, address, the job role (lecturer, advisor, course
developer),
developer) and also qualifications (pedagogical, administrative, and
(pedagogical administrative
professional subject-related competence). In addition to this, one
needs information whether the lecturer works full-time or part-time,
how much he earns, whether he/she is married, and whether she/he
does active research.
Concerning the courses, we need to uniquely identify the course
with some identifier, we must have the course name and course
description. In addition to this, we must make some restrictions on
the number of students on the course. Some of the courses require
audio-visual equipment; hence, they must be conducted in
q p y
especially equipped rooms having a limited number of seats. Finally,
one must know, which lecturer teaches on which course.
Regarding the books, we must have some kind of an identifier and
g g
title. We must also know their price and on which course they are
being utilised.
36. Case Study: thuộc tính
Phân tích Thiết kế HĐT
Student
St d t Teacher
T h Course
C
pnr: Integer pnr: Integer course_number: Integer
student_name: String teacher_name: String course_name: String
address: String role: String
course_description: String
p g
nationality: St i
ti lit String ped_competence: String
d t St i
degree_level: String admin_competence: String no_of_students: Integer
grade: Integer prof_competence: String teacher_name: String
IQ_kvot: Integer percentage_of_full_time: Integer equipment_type: String
$average_age: Integer salary: Integer
martial_state:
martial state: String
research_engagement: String
Book
book_number: Integer
ISBN_number: String
title: String
price: Real
37. Các khái niệm cơ bản
Phân tích Thiết kế HĐT
Object
Class
Cl
Attribute
Operation
Relationships
Interface (Polymorphism)
37
38. Xác định tác vụ
Phân tích Thiết kế HĐT
Person
pnr: Integer
name: String status Compartment 1 .
p
birth_date: Integer Compartment 2
address: String • class properties
teaches: Course • peer-to-peer relationships
name()
operate on Compartment 3
age()
address()
behaviour
change_address(new_address)
Objects manage their own data
using their own operations
i th i ti
39. Tác vụ (Operation)?
CourseOffering
Class
addStudent
deleteStudent
getStartTime
Operation getEndTime
39
40. Thông điệp (message)
Phân tích Thiết kế HĐT
Thông điệp là một phép gọi tác vụ của một đối
tượng
tượ cụ thể
thể.
Thông điệp bao gồm 3 phần
Đối tượng đích
ố í
Dấu hiệu nhận dạng của tác vụ muốn gọi
Danh á h thô
D h sách thông số gọi
ố i
Ví dụ: aCircle.SetRadius(3);
aCircle.Draw(pWnd);
aCircle Draw(pWnd);
40
41. Course Method
Phân tích Thiết kế HĐT
course_number: String
course_name: String
no_of_students: Integer
teacher_name: String A method can change the characteristics
of one or several attributes
change-teacher(teacher_name)
remove-teacher(Teacher)
It may create, change, or remove the
check_Number of students object’s links to other objects
It may control some status of the
object’s attributes
State
St t 1
Polish: Course
PPP234
Polish State 2 ID: 434356
12 Polish: Course Göran Persson: Student
Adamski
PPP234 2312302456
Polish Göran Persson
12 95
Szczyperski
Methods are constrained by the value of object attributes and links when they is
invoked.
42. Person Tác vụ ở mức thể hiện
Phân tích Thiết kế HĐT
pnr: Integer
name: String
birth_date: Integer
address: String
name()
243543948
age() Pelle
address()
change_address(new_address)
g _ ( _ ) 7812233455
Pelle Jansson
781223
Uses the method stored Laxgatan 23, 187 88 Hagsätra
in the class object
Changes the data stored in
the instance object
Pelle.change_address(Karpgatan 25, 345 43 Älvsjö)
Objects store only data. Classes store methods.
When an operation must be performed on an object, a
call to the class method is being made.
43. Operation và method
Phân tích Thiết kế HĐT
Class name
Object attributes
method
Object operations implemented by
p y …………….
method
……………..
UML notation …………….
………………
method
……………..
……………… …………….
……………..
………………
44. Tác vụ thật sự ?
Phân tích Thiết kế HĐT
Vài hoạt động được mô hình tốt hơn dưới dạng
Lớp giao dịch
pg ị
• Chứa các đặc trưng dưới dạng thuộc tính của
lớp
• Lưu giữ các thông tin giao dich (sales over a
period of time, e.g. in order to respond to
warranty claims, or to audit the shop’s
accounts))
Nếu không lưu giữ thông tin về giao dịch thì có
thể sử dụng tác vụ của một lớp (không cần phải
đưa ra lớp riêng)
45. Hướng dẫn tìm tác vụ
Phân tích Thiết kế HĐT
The most important thing is not to expect to get things right at the
first attempt You will always need to revise your assumptions and
attempt.
models as your understanding grows.
Hình d
Hì h dung mỗi lớp như một actor độ lậ có nhiệm
ỗi lớ h ột t độc lập ó hiệ
vụ làm hay hiểu một điều xác định nào đó
Đặt tác vụ trong lớp chứa dữ liệu mà nó cần cho
việc update hay truy cập
Chú ý tới việc chưa xác định đầy đủ tất cả các thuộc
tính
46. Case Study: xác định tác vụ (1)
Phân tích Thiết kế HĐT
On the former lecture, we modelled the educational
material. So far, we have only designated the classes.
, y g
Supplement them with relevant attributes and operations.
To give you some idea, the educational material may be
operated on in the following:
- it must be accessed and displayed. Here different data
such as ID, ISBN, author, title, keywords, sections and
paragraphs may be displayed.
- its size must be computed in number of words.
- it cost must be available. Please observe that the
its t tb il bl Pl b th t th
conference articles and internal technical reports do not
cost anything.
47. Case Study: xác định tác vụ (2)
Phân tích Thiết kế HĐT
- you must assess the readability of the publications. When
doing this, the linguistic quality and style must be
g , g q y y
evaluated. Assume here that there is a special routine that
is able to check the spelling, and the style of the teaching
material.
material Please observe that you don’t need to do this for
don t
books. Their readability has already been checked by the
editors.
- the international publications are usually scientifically
graded on the scale 1-10. The more series publication the
higher the grade. When choosing the course literature, one
wishes to eliminate the publications having grades lower
than 5. To be able to do this, one must access their grades
48. Các khái niệm cơ bản
Phân tích Thiết kế HĐT
Object
Class
Cl
Attribute
Operation
Relationships
Interface (Polymorphism)
48
49. Relationship: links
Phân tích Thiết kế HĐT
´This link
expresses a
p
logical connection
between a student
and a course
ID: 44000122 ID: 434356
Polish: Course Göran Persson: Student
PPP234 2312302456
Polski Göran Persson
12 95
Adamski
A link is a relationship between two objects.
objects
50. Relationship: associations
Phân tích Thiết kế HĐT
Course Student
course_number: String pnr: Integer
course_name: Stringg student_name: String
g
no_of_students: Integer IQ_kvot: Integer
teacher_name: String reads
Class level
Instance level
ID: 44000122 ID: 434356
Polish: Course Göran Persson: Student
PPP234 2312302456
Polski Göran Persson
12 95
Adamski
An association is a relationship between classes.
51. Các khái niệm cơ bản
Phân tích Thiết kế HĐT
Object
Class
Cl
Attribute
Operation
Relationships
Interface (Polymorphism)
51
52. Giao diện (Interface)?
Phân tích Thiết kế HĐT
Giao diện hình thành đa hình
Giao diện
Gi diệ hỗ t ợ kiế t ú “ l
trợ kiến trúc “plug-and-play”
d l ”
Tube
<<interface>>
Shape
Pyramid
Draw
D
Move
Scale
Rotate Cube
Realization relationship
53. Interface và Đa hình (Polymorphism)?
Phân tích Thiết kế HĐT
Khả năng che dấu nhiều việc thực thi khác nhau dưới một
giao diện (interface) duy nhất
Manufacturer B
Manufacturer A Manufacturer C
OO Principle:
Encapsulation
53
54. Giao diện
Tube
Pyramid
Shape Cube
Tube
<<interface>>
Shape
p
Pyramid
Draw
Move
Scale
Rotate Cube
54
55. Lớp trừu tượng và phương thức trừu tượng
(Abstract Class và Abstract Method)
Phân tích Thiết kế HĐT
Account
public abstract class Account accNo
{ balance
protected int accNo; balance( )
protected int balance; withdraw( )
public Account(int an, int b){ Savings
accNo = an;
balance = b; Cheque
} ODLimit
ODLi it
withdraw( )
public int balance(){
return balance; withdraw( )
}
public abstract void withdraw(int amount);
}
55
56. Chồng, thừa kế, sử dụng lại
(Overriding, Inheritance, Reusing)
Phân tích Thiết kế HĐT
Account
accNo
public class Savings extends Account balance
{ balance( )
public Savings(int an, int b) withdraw( )
{
super (an, b); Savings
}
Cheque
public void withdraw(int amount) ODLimit
ODLi it
withdraw( )
{
if (balance > amount) withdraw( )
balance -= amount;
b l t
}
}
56
57. Chồng và biến của lớp
(Overriding, Class Variable)
Phân tích Thiết kế HĐT
Account
accNo
public class Current extends Account balance
{ balance( )
private static int ODlimit=100; withdraw( )
p
public Current(int an, int b)
( , )
{ Savings
super (an, b);
} Cheque
public void withdraw(int amount) ODLimit
ODLi it
withdraw( )
{
if (balance+ODlimit > amount) withdraw( )
balance -= amount;
=
}
}
57
58. Thời gian chạy và đa hình thừa kế
Run-
Run-time và inherited polymorphism
Phân tích Thiết kế HĐT
Account
import java.io.*;
public class withdrawCtrl
accNo
{ balance
public Account getAccount() throws IOException { balance( )
int d =2; withdraw( )
Account A;
if (d==1)
A= new Savings(100, 1000); Savings
else Cheque
A= new Current(120,2000);
Current(120 2000); ODLimit
ODLi it
return A; withdraw( )
}
withdraw( )
public void withdrawCtr() throws IOException {
Account A;
A=getAccount();
int amount =100;
100;
A.withdraw(amount); System.out.println (A.balance());
}
} 58
59. 2. Biểu đồ lớp
1. Biểu đồ lớp ?
2. Biểu diễ
2 Biể diễn quan hệ ( l ti
(relationship)
hi )
59
60. Biểu đồ lớp và đối tượng
Phân tích Thiết kế HĐT
60
61. Class và Object
Phân tích Thiết kế HĐT
Account Name of
Class Class
variable aNo
balance Data
balance(?) dayLimit = 200 Declaration
SamAcc:: soFar
withdraw(X) aNo=101 balance( )
balance=500
withdraw( ) Methods
soFar=100
Definition
---
instances
SamAcc::Accoun Name of
MicAcc::Accoun Name of
t Object
aNo = 101 t Object
aNo = 105
balance = 500
balance = 600
soFar=100 Data Values
soFar 200
soFar=200 Data Values
61
62. Lớp và đối tượng
Phân tích Thiết kế HĐT
Một đối tượng biểu diễn cho một thực thể có thể
là thực thể vật lý khái niệm hay là phần mềm…
lý, mềm
Một đối tượng là một khái niệm, sự trừu tượng
hay một vật mà có ranh giới rõ ràng, và có nghĩa
rõ rệt cho một ứng dụng
Một lớp là một mô tả cho một nhóm các đối tượng
có chung thuộc tính, ứng xử, mối quan hệ và ngữ
nghĩa (semantic).
Lớp là một khuôn mẫu để tạo ra đối tượng
Mỗi đối tượng trong một hệ thống đều có ba đặc
tính: trạng thái, ứng xử và danh định.
62
63. Trạng thái (state)
Phân tích Thiết kế HĐT
Trạng thái của một đối tượng là một trong những
tình t
tì h trạng mà đối tượng có thể tồ t i trong môi
à tượ ó tồn tại t ôi
trường.
Trạng
T ng thái của một đối tượng thường sẽ thay đổi
ủ ẽ th
theo thời gian, trạng thái của đối tượng thường
được được gắn với thời điểm
điểm.
Trạng thái của một đối tượng được xác định qua
một tập các thuộc tính, và mối quan hệ với các
đối tượng khác.
63
64. Hành vi (Behaviour) và Danh định (Identity)
Phân tích Thiết kế HĐT
Hành vi xác định một hoạt động của một đối
tượng (thay
tượ (th đổi trạng thái theo thời gian) nhằm
t th i ) hằ
đáp ứng các yêu cầu từ các đối tượng khác, nó
tiêu biểu cho những gì mà đối tượng này có thể
làm
Danh định dùng để phân biệt giữa các đối tượng
ngay cả khi nó có cùng trạng thái và giá trị các
thuộc tính
ộ
64
65. Tính khả kiến
Phân tích Thiết kế HĐT
Nếu thuộc tính có tính khả kiến là công cộng (public +),
thì nó có thể được nhìn thấy và sử dụng ngoài lớp đó
Nếu thuộc tính có tính khả kiến là riêng (private -), bạn sẽ
không thể truy cập nó từ bên ngoài lớp đó
Nếu thuộc tính có tính khả kiến là bảo vệ (protected #) thì
cũng giống như thuộc tính có tính khả kiến là riêng nhưng
là công cộng đối với các lớp con
65
66. Biểu đồ lớp (class diagram)
Phân tích Thiết kế HĐT
Độc lập với ngôn ngữ
Những ký hiệu cho phép đặc tả lớp, dữ liệu hay
thuộc tính của chúng (private) và phương thức
(method), ự thừa kế…
(method) sự thừ kế
Những sơ đồ đưa ra những hình ảnh về quan hệ
cấu trúc và những ứng xử về chức năng của các
lớp
66
67. Mục đích của biểu đồ lớp
Phân tích Thiết kế HĐT
Làm tài liệu cho các lớp cấu thành hệ thống và hệ
thống
thố con
Mô tả kết hợp, tổng quát hóa và các quan hệ kết
tập giữa các lớp trong biểu đồ
giữ á t ong biể
Chỉ rõ đặc trưng của lớp, các thuộc tính và tác vụ
chính của mỗi lớp
Biểu đồ lớp được dùng khắp nơi trong chu trình
phát triển, từ bài toán đến mô hình cài đặt
triển
67
68. Các lớp dự tuyển (*)
Phân tích Thiết kế HĐT
68
69. Nội dung
Biểu diễn Lớp và đối tượng
Biểu diễ
Biể diễn quan hệ (relationship)
( l ti hi )
69
70. Quan hệ (relationship)
Phân tích Thiết kế HĐT
Kết hợp (Association)
Kết tập (aggregation)
Kết cấu (Composition)
Phụ thuộc (Dependency)
Chuyên biệt và tổng quát hóa
(Specialization/Generalization)
70
71. Kết hợp (Association)
Phân tích Thiết kế HĐT
Association Name
Professor University
Works for
Role Names
Class Professor University
Employee Employer
71
72. Những ràng buộc của kết hợp
Phân tích Thiết kế HĐT
Một kết hợp phải có một tên đặt bên trên hay kề
với đường liên hệ
ới đườ liê
Tên của kết hợp phải phản ảnh nội dung, là cụm
động từ, tên có thể bỏ q đặ biệt khi tên vai trò
từ ó qua đặc itò
của nó được dùng, tránh dùng tên không cộng
thêm thông tin
Mỗi đầu của kết hợp là một vai trò (role) chỉ ra vai
trò của lớp trong kết hợp, tên vai trò phải là duy
nhất ứng với một lớp, tên vai trò phải là một danh
từ đặt cuối đường kết hợp
Chọn một trong hai: tên kết hợp hay tên vai trò
72
73. Vai trò
Phân tích Thiết kế HĐT
Course plays two roles:
• taught-by
• managed-by
Course
C teaches
t h taught-by
t ht b Lecturer
L t
course_number: String teaches pnr: Integer
course_name: String student_name: String
no_of_students:
no of students: Integer IQ kvot: Integer
Q_ g
teacher_name: String is_in_charge_of managed_by
manages
One class may have many roles.
roles
74. Kết hợp đệ qui
Phân tích Thiết kế HĐT
Tên vai trò là bắt buộc
74
75. teaches
Association degree
Student Phân tích Thiết kế HĐT
pnr: Integer
student_name: String
IQ_kvot: Integer
A unary association
Course Student
A binary association
course_number: String pnr: Integer
course_name: String student_name: String
no_of_students: Integer IQ_kvot: Integer
teacher_name: String reads
An association may be unary binary or ternary
unary, binary,
76. Bản số (Multiplicity)
Phân tích Thiết kế HĐT
Xác định bao nhiêu đối tượng tham gia kết hợp
Many
M
One or more
76
77. Lớp kết hợp (Association class)
Phân tích Thiết kế HĐT
1..* 0..* card
account
UsedFor
Associatio
dateIncluded n
class
0..* 1..* course
student
No Name
grade
77
78. Kết tập (aggregation)
Phân tích Thiết kế HĐT
Kết tập là quan hệ giữa toàn bộ và bộ phận
Một đối tượng đượ t từ những đối tượng khá có
tượ được tạo hữ tượ khác ó
tính vật lý
Một đối tượng là tập hợp của những đối tượng khác có
tính logic
Một đối tượng chứa những đối tượng khác có tính vật lý
Whole
Part
Student Schedule
Aggregation
78
79. Case study: Xác định lớp kết hợp (1)
Phân tích Thiết kế HĐT
Students at SU may read many different courses. The
students however, should not read more than five
,
courses during one semester. A course may be given on
several occasions per semester. For each occasion,
different teachers may be involved on the course This
course.
implies that these teachers may choose different course
literature. The choice of the book does not only depend
on th t
the teacher, b t also on the students’ average IQ
h but l th t d t ’
value.
A course may only start if there are at least 15 students
reading this course. Otherwise, the course must be
cancelled. Teaching for less than 15 students would be
too expensive
expensive.
80. Case study: Xác định lớp kết hợp (2)
Phân tích Thiết kế HĐT
The courses are taught by lecturers. The fact that you
are a lecturer does not hinder you from reading courses
at university. There may be cases that a lecturer reads
and teaches on one and the same course
simultaneously.
sim ltaneo sl This is in cases when the lect e is a
hen lecturer
PhD student. The work he has put into developing and
teaching on a course gives him credit point within his
PhD studies.
81. Student 0..*
Teacher
pnr: Integer Phân tích Thiết kế HĐT
student_name: String pnr: Integer
$average_IQ: String lecturer_name: String
reads ↓ …...
1..1
reads ↓ 1..5 taught_by ↑
1..5
Course Occassion
reads
start_date: Date
finish_date: Date Course Occassion
1..*
corresponds to the
uses_book association class in an
association of degree 4.
4
15..*
1..*
offered_by ↑
Book
Course
book_number: Integer
ISBN_number: String course_number: Integer
title: String course_name: String
price: Real course_description:
course description: String
1..1
82. Composition (kết cấu)
Phân tích Thiết kế HĐT
Kết cấu là một dạng của kết tập, thời gian sống
của đối tượng bộ phận không vượt quá thời gian
sống của đối tượng toàn bộ
Khi toàn bộ bị xóa thì bộ phận cũng bị xóa
Bộ phận có thể bị xóa trước khi toàn bộ bị xóa
Whole Part
Student
St d t Schedule
S h d l
Aggregation
82
85. Phụ thuộc (Dependency)
Phân tích Thiết kế HĐT
Một biến đổi trên một thành phần sẽ gây ra sự
biến đổi trong thành phần khác
Client Supplier Componen
Class
t
Package Client Supplier
Dependency
relationship
ClientPackage SupplierPackage
Dependency
relationship
85
86. Specialization/Generalization
Phân tích Thiết kế HĐT
Chuyên biệt hóa(/tổng quát hóa): là quá trình
tinh chế một lớp thành những lớp chuyên biệt hơn
hơn.
Chuyên biệt hóa bổ sung thêm chi tiết và đặc tả
cho lớp kết quả. Lớp mang tính khái quát được gọi
là lớ cha (
lớp h (superclass), kế quả chuyên biệ hó
l ) kết ả h ê biệt hóa
là việc tạo ra các lớp con (Subclass).
Tổng quát hóa và chuyên biệt liên quan tới Thừa
kế (Inheritance)
Lớp con thừa kế attributes, operations, và relationships
p p p
Lớp con có thể:
• Cộng thêm attributes, operations, relationships
• Xác định lại tác vụ được thừa kế (ca tion!)
(caution!)
86
87. Generalisation/specialisation
Phân tích Thiết kế HĐT
Often we find similar properties or
Person terms in the Universe of
Discourse, which however, are not
, ,
exactly the same
Student Teacher
Class
Object
Ulla Rask
Anna Bok
Sven Lund
Erik Gadd
Olle Macho
88. Generalisation/specialisation
Phân tích Thiết kế HĐT
Person
Student Teacher
Class
Object
Anna Bok
Ulla Rask Sven Lund
Erik Gadd
Olle Macho
89. Existence dependency
Hand Phân tích Thiết kế HĐT
is_part_of
* has
Finger Transitivity
object A contains object B,
and object B contains object
is_part_of C, then A contains C.
Asymmetry
A t
* has
if A contains B, then B
Nail
cannot contain A.
A
92. Thừa kế
Phân tích Thiết kế HĐT
Abstraction Person More general
(superclasses)
Employee Customer Supplier
Subclasses are fully
weeklyy hourly
y Consistent with
monthly
paid paid super classes and
paid
add more
information
Driver Cleaner Sales
assistant More specialized
Real-world entities on
R l ld titi (subclasses)
( b l )
leaves
94. Thừa kế đơn
Phân tích Thiết kế HĐT
Ancestor
Account
balance
name
Superclass number
(parent) Withdraw()
CreateStatement()
Generalizatio
n Relationship
Checking Savings
Subclasses Withdraw() GetInterest()
Withdraw()
Descendents
94
95. Đa thừa kế
Phân tích Thiết kế HĐT
FlyingThing Animal
multiple
inheritance
Airplane Helicopter Bird Wolf Horse
Use multiple inheritance only when needed, and
always with caution !
95
96. Ví dụ
GroundVehicle
G dV hi l
owner Person
Superclas weight
s (parent) licenseNumber 0..* 1
register( )
generalization
Car Truck Trailer
Subclass size tonnage
getTax( )
96
97. Lớp trừu tượng
Phân tích Thiết kế HĐT
Person
(abstract)
pnr: Integer
name: String
birth_date: Integer
address: String Abstract classes
create a hi h
high-
level modelling
vocabulary.
vocabulary
Student Teacher
IQ-value: Integer Ped_skill: Integer
student_points: Integer
t d t i t I t experience: Integer
i I t
98. Ràng buộc
Phân tích Thiết kế HĐT
Cho phép cộng thêm ngữ nghĩa mới
Ràng b ộ
Rà buộc là một St i đóng trong ngoặc nhọn
ột String đó t ặ h
đặt gần thành phần mà nó áp dụng
Dùng
Dù quan hệ phụ thuộc nếu có nhiều thành phần
h th ộ ế ó hiề thà h hầ
mà ràng buộc áp dụng
Member Department
Professor
{Subset}
Deparment Head
98
99. Phân loại trong Kế thừa
Phân tích Thiết kế HĐT
4 loại (ràng buộc)
Disjoint
Overlapping
Complete
Incomplete
99
100. Thừa kế và tổng quát hóa
Phân tích Thiết kế HĐT
100
101. Phân loại
Phân tích Thiết kế HĐT
Student
Disjoint?
j Overlapping
pp g
Membe ? Internal Local
r
Staff Student
Discriminator
Student
type
Complete? mode
Student Internationa Local PGrad UGrad
l s s
Asian
sa Local
oca
LocalPGrad
L lPG d
s
102. Xác định aggregation
Phân tích Thiết kế HĐT
Sometimes, the teachers cannot utilise the
whole b k during th i courses, only parts
h l books d i their l t
of it. This is because for some courses it may
be difficult to find an optimal book. Not every
p y
teacher has time to write specifically tailored
own material. Hence, the teaching material
consists of different book chapters or even
book sections. Due to the fact that the
material conveyed in these books may quickly
age (t i l within computer science), th
(typical ithi t i ) the
constellation of the teaching material often
g
changes.
103. Book
0..* Phân tích Thiết kế HĐT
1..1 is_part_of
0..*
1..* has
Chapter Course Literature
0..* 1..*
1..1 is_part_of
0..*
1..
1 * has
Section
0..*
104. Study case: generalisation/specialisation (1)
Phân tích Thiết kế HĐT
The teaching material does not only consist of books.
books
Teaching material can be anything:
- books, or parts of books as has already been
modelled.
- national publications, such as technical reports and
working articles
articles.
- different kinds of international publications such as
journal-, conference- or workshop papers.
105. Study case: generalisation/specialisation (2)
Phân tích Thiết kế HĐT
SU wishes to record this information so that one can clearly
see the constellations of teaching material. Irrespective of
whether it was internationally published or not, whether it
was a book or report, and whether some of this teaching
material was written by the teachers involved on the course.
SU also wishes to know all the roles involved in teaching.
They are course leaders, course executors, advisors,
assistants. I addition, we have varying groups of students.
i t t In dditi h i f t d t
We have Swedish and foreign exchange students. Regarding
the Swedish students, they need not be necessarily originally
, y y g y
Swedish. The prerequisite for being classified as a Swedish
student is that the student lives permanently in Sweden.
106. Study case: biểu đồ
Phân tích Thiết kế HĐT
Course
Literature
Publication
Book 0..*
1..1 is_part_of
0..*
1..* has National International
Publication Publication
Chapter Book
0..* 1..*
Literature
1..1 is_part_of
0..* Technical Working Conference Journal Worksho
1.. has
1 *h Report Paper Article Article p
Article
Section 0..*
107. Biểu đồ
Phân tích Thiết kế HĐT
Course
Literature
Educational
Material
0..* 0..*
0..* Publication
Book 0..*
1..1 is_part_of
1 1 is part of
0..*
0..*
1..* has National International
Publication Publication
Chapter 0..* 1..* Book
Literature
1..1 is_part_of
0..* Technical Working Conference Journal Workshop
1..* has Report Paper Article Article Article
Section 0..*
108. Biểu đồ lớp Person
Phân tích Thiết kế HĐT
SU also wishes to know all the Person
roles involved in teaching.
They are course leaders,
course executors, advisors,
course developers, assistants.
In addition, we have varying
group of students.
Student Teaching
T hi
Staff
Swedish Foreign Course Course Advisor Assistant
Student Student leader Executor
Native Non-native
Swedish Swedish
Student Student
109. Bài tập
Phân tích Thiết kế HĐT
Books and journals The library contains books
and journals. It may have several copies of a
given book.
Some of the books are for short term loans only.
All other books may be borrowed by any library
member for three weeks. Members of the library
can normally borrow up to six items at a time, but
y p ,
members of staff may borrow up to 12 items at
one time. Only members of staff may borrow
journals.
journals
Borrowing The system must keep track of when
books and journals are borrowed and returned,
enforcing the rules described above.
109
114. Câu hỏi
Phân tích Thiết kế HĐT
Giải thích một số khái niệm về hướng đối tượng?
Khác biệt giữa lớp và đối tượng ?
Lớp dẫn xuất ?
Lớp kế thừa những gì ?
Quan hệ của lớp ?
Các loại quan hệ ? Ràng buộc giữa các quan hệ ?
Phân loại trong kế thừa?
ạ g
114
115. Thực hành
Phân tích Thiết kế HĐT
Phát hiện thực thể và các tương tác của các hệ
thống
thố
Hệ thống Thay thế tài xế
Hệ thống
thố Khảo thí
Khả
Hệ thống Quản lý kho
Hệ thống
thố Safe H
S f Home
Hệ thống Thư viện trực tuyến
Hệ thống ATM
Hệ thống Đấu giá
Hệ thống Tính công Xí nghiệp may…
may
115