2
UML
UML ( Unified Modeling Language)
หมายถง ภาษารปภาพทท าการก าหนดลกษณะของ class และการสราง class รวมถงเปนเอกสารทบอกถงรายละเอยดของระบบโครงสรางโปรแกรม
3
UML ขอดของ UML • เปนภาษารปภาพมาตราฐานหรอภาษาสากลทใชในการพฒนาซอฟตแวรเชงวตถ
• ไมผกตดกบภาษาโปรแกรมภาษาใดภาษาหนง
• เปนภาษาทงายตอการท าความเขาใจ
• แปลงเปนภาษาทใชสรางระบบงานไดอยางอตโนมต
• เปนการเขาใจปญหาและคนพบทางแกปญหาไดอยางรวดเรวและงายขน
• เปนเอกสารทพรอมน าไปปรบปรงแกไขไดอยางรวดเรว
4
UML องคประกอบของ UML 1. สญลกษณทวไป(Things)
• หมวดโครงสราง (Structural) ไดแก ยสเคส คลาส อนเทอรเฟซ
คอมโพเนนต คอลแลบอเรชน และโหนด
• หมวดพฤตกรรม (Behavioral)ไดแก อนเตอรแอกชน สเตตแมชชน
• หมวดจดกลม (Grouping)ไดแก แพกเกจ
• หมวดค าอธบายประกอบ(Annotational) ไดแก โนต (Note)
5
UML องคประกอบของ UML 2. ความสมพนธ (Relationships)
• ความสมพนธแบบพงพา (Dependency Relationship)
• ความสมพนธแบบเกยวพนธ (Association Relationship)
• ความสมพนธแบบเจเนอรลไลเซชน (Generalization Relationship)
หรอความสมพนธแบบไมเจาะจง
ไดแก ความสมพนธแบบสบทอดคณสมบต (Inheritance)
6
UML องคประกอบของ UML 3. ไดอะแกรม (Diagrams)
• Use Case Diagram เปนโมเดลฟงกชนการท างานของระบบ
• Class Diagram เปนโมเดลคลาสตาง ๆ ทจ าเปนตอระบบ
• Activity Diagram มหลกการเดยวกบ Flowchart
• Statechart Diagram ใชส าหรบแสดงสถานะของ Object ในระหวางท างาน
• Collaboration Diagram ใชแสดงการท างานรวมกนของ Object ในระบบ
7
UML องคประกอบของ UML 3. ไดอะแกรม (Diagrams)ตอ
• Sequence Diagram ใชเปนโมเดลกจกรรมตาง ๆ
ทเกดขนกบ Object ในระบบ
• Component Diagram ใชส าหรบสรางโมเดล Component ในระบบ
• Deployment Diagram ใชแสดงการตดตงใชงานสวนประกอบของระบบ
8
Construct Description Syntax
class a description of a set of objects that share the same attributes, operations, methods, relationships and semantics.
interface a named set of operations that characterize the behavior of an element.
component a physical, replaceable part of a system that packages implementation and provides the realization of a set of interfaces.
node a run-time physical object that represents a computational resource.
«interface»
Structural Modeling: Core Elements
9
Structural Modeling: Core Elements (cont’d)
Construct Description Syntax
constraint¹ a semantic condition or restriction.
{constraint}
10
Construct Description Syntax
association a relationship between two or more classifiers that involves connections among their instances.
aggregation A special form of association that specifies a whole-part relationship between the aggregate (whole) and the component part.
generalization a taxonomic relationship between a more general and a more specific element.
dependency a relationship between two modeling elements, in which a change to one modeling element (the independent element) will affect the other modeling element (the dependent element).
Structural Modeling: Core Relationships
11
Use Case Diagram คนหาวาระบบท าอะไร โดยไมสนใจกลไกการท างานหรอเทคนค
เปรยบเสมอน BLACK BOX กลองด า
ประโยชน
• ทราบความสามารถของระบบ
• ทราบผใชงานในแตละสวนของระบบ
• งายตอการสอสารระหวางลกคาและผพฒนาระบบ
• ใชทดสอบระบบวาตรงตามความตองการของระบบหรอไม
12
Use Case Modeling: Core Elements Construct Description Syntax
use case A sequence of actions, including variants, that a system (or other entity) can perform, interacting with actors of the system.
actor A coherent set of roles that users of use cases play when interacting with these use cases.
system boundary
Represents the boundary between the physical system and the actors who interact with the physical system.
UseCaseName
ActorName
UML: PART 1 13
Construct Description Syntax
association The participation of an actor in a use case. i.e., instance of an actor and instances of a use case communicate with each other.
generalization A taxonomic relationship between a more general use case and a more specific use case.
extend A relationship from an extension use case to a base use case, specifying how the behavior for the extension use case can be inserted into the behavior defined for the base use case.
Use Case Modeling: Core Relationships
<<extend>>
14
Construct Description Syntax
include An relationship from a base use caseto an inclusion use case, specifyinghow the behavior for the inclusion usecase is inserted into the behaviordefined for the base use case.
Use Case Modeling: Core Relationships (cont’d)
<<include>>
15
องคประกอบUse Case Diagram
1. Use Case
• ระบบใน Use Case Diagram แสดงดวยรปกลองสเหลยม
ซงบรรจสญลกษณ Use Case อยภายใน
และมชอของระบบเขยนอยขางบนหรอขางในกลอง
Telephone Catalog
16
องคประกอบ ของ USE CASE DIAGRAM
2. Actor
• ผทกระท ากบระบบ โดยอาจเปนคนหรอไมกได
• เชน นกศกษาพมพชอหนงสอเขาไปในระบบเพอคนหนงสอในหองสมด
และรอรบผลการคนหา
ดงนน นกศกษาจดเปน Actor
17
องคประกอบ ของ USE CASE DIAGRAM
2. Actor
แบงเปน 2 ประเภท
• แอกเตอรหลก หมายถง แอกเตอรทมความส าคญโดยตรงตอความสามารถ
หลกของระบบ ซงแสดงดวย Use Case ถอวาส าคญสด
• แอกเตอรรอง หมายถง แอกเตอรทมหนาทความส าคญรองลงไปจาก
แอกเตอรหลก
19
องคประกอบ ของ USE CASE DIAGRAM
2. Actor
ความสมพนธระหวางแอกเตอร (Relationship)
หากแอกเตอรหลายแอกเตอรในระบบซงมคณสมบตคลาย ๆ กน สามารถแยก
ออกมาเปนอกแอกเตอรหนงทรวมบทบาททเหมอนกนของแตละแอกเตอร ซงเปนคณ
สมบตพนฐาน (General) เสมอนเปน ซปเปอรคลาส (Superclass)
แอกเตอรพนฐานจะถกสบทอด (Inherit) จากแอกเตอรอน เรยกวา Generalization
20
องคประกอบ ของ USE CASE DIAGRAM
2. Actor
ความสมพนธระหวางแอกเตอร (Relationship)
ตวอยางเชน ในระบบหนงม 3 แอกเตอรคอ
* ลกคา(Customer)
* ลกคาทสงซอทางโทรศพท (Telephone Customer)
* ลกคาทเดนทางมาดวยตนเอง (Personal Visit Customer)
21
องคประกอบ ของ USE CASE DIAGRAM
2. Actor
ความสมพนธระหวางแอกเตอร (Relationship)
ในระบบนลกคาทสงซอทางโทรศพทและลกคาทเดนทางมาดวยตนเอง
ตางกมบทบาทพนฐานเดยวกนกคอเปนแอกเตอรลกคาเหมอนกน
Customer
Telephone Customer Personnal Visit Customer
ใชลกศรหวโปรงช
22
Use Case Diagram
ตวอยาง Telephone Catalog
Check Status
Place Order Sales Person
Customer Fill Order Shipping Clerk
Establish Credit Supervisor
23
Use Case Relationships
additional requests :
OrderProduct
SupplyArrange
«include»«include»«include»
RequestCatalog
«extend»Extension points
PaymentCustomer Data
after creation of the order
Place Order
1 * the salesperson asks forthe catalog
25
องคประกอบ ของ USE CASE DIAGRAM
1. Use Case ยสเคส
ใชสญญลกษณรปวงร มชอยสเคสอยขางใน และทกยสเคสอยภายใตกรอบ
สเหลยม ดงน
Check Status
Place Order
26
องคประกอบ ของ USE CASE DIAGRAM
3. ความสมพนธระหวางยสเคส
1. ความสมพนธแบบขยาย (Extend Relationship)
ยสเคสหนงอาจถกชวยเหลอโดยการท างานยสเคสอน
เชน ยสเคสการใสรหสอาจถกชวยเหลอโดยยสเคสค าอธบายการใสรหส
สญลกษณใน UML คอลกศรเสนประทชจากยสเคสแรกไปยงยสเคสทถกชวยเหลอหรอถกขยาย โดยมค าวา extend อยในเครองหมาย << >>
27
องคประกอบ ของ USE CASE DIAGRAM
3. ความสมพนธระหวางยสเคส
1. ความสมพนธแบบขยาย (Extend Relationship)
Place Order
<< extend>>
the salesperson asks for the catalog
Request Calalog
28
องคประกอบ ของ USE CASE DIAGRAM
3. ความสมพนธระหวางยสเคส
2. ความสมพนธแบบรวม (Include Relationship)
ยสเคสหนงอาจจ าเปนตองอาศยการท างานของยสเคสอน
ส าหรบยสเคสทถกเรยกใชโดยยสเคสอน แทนดวย << include>> ทกงกลางลกศร
Signing Insurance Policy
Signing Car Insurance Signing Life Insurance <<include>> <<include>>
29
ตวอยาง
Withdraw cash
Check Balance
Print mini-statement Customer
Use Case Diagram for ATM subsystem
30
Online HR System:
Update Benefits Use Case Actors: employee, employee account db, healthcare plan system, insurance plan system
Preconditions:
Employee has logged on to the system and selected ‘update benefits’ option
Basic course System retrieves employee account from employee account db
System asks employee to select medical plan type; include Update Medical Plan.
System asks employee to select dental plan type; include Update Dental Plan.
…
Alternative courses
If health plan is not available in the employee’s area the employee is informed and asked to select another plan...
UML: PART 1 31
Example: Online HR System
Online HR System
Locate
Employees
Update
Employee
Profile
Update Benefits
Access Travel
System
Access Pay
Records
Employee
Manager
Healthcare Plan System
{if currentMonth = Oct.}
{readOnly}
Insurance Plan System
UML: PART 1 32
Online HR System: Use Case Relationships
Update Medical
Plan
Update Dental
Plan
Update Benefits______________
Extension points
benefit options:
after required enrollments
Update
Insurance Plan
Employee
<<include>> <<include>> <<include>>
Elect
Reimbursement
for Healthcare
Elect Stock
Purchase
<<extend>>
employee requests
stock purchase option
<<extend>>
employee requests
reimbursement option
extension
condition
extension point
name and
location
33
UML : Class Diagram Class Diagram • เปน Diagram ทแสดงองคประกอบทงหมดของระบบ
Object
• คอทกสงทเรามองเหน เชน คน สงของ เครองจกร ไฟล
Class
• ชนดของกลม Object
• ตวอยาง ของคลาส: ระบบซอฟตแวร มคลาส ไฟล ไอคอน วนโดว เมาส
34
UML : Class Diagram สญลกษณ UML แสดงคลาส
Class Name
attribute(s)
operation(s)
1. Class Name จะขนตนดวยอกษรตวใหญแบบหนา และจะเอยงหากเปน
Abstract Class
35
UML : Class Diagram สญลกษณ UML แสดง Class (ตอ) 2. สวนส าหรบ Attribute
• ชนดของการเขาถง (Visibility) ของ Attribute ไดแก
• ชนด Public แทน +
• ชนด Private แทน -
• ชนด Protect แทน #
36
UML : Class Diagram สญลกษณ UML แสดง Class (ตอ) 2. สวนส าหรบ Attribute
• ชอของ Attribute
• ประเภทของ Attribute จะอยตอจากเครองหมาย : เชน Integer Real
• คาเรมตน Attribute จะอยตอจากเครองหมาย =
37
UML : Class Diagram สญลกษณ UML แสดง Class (ตอ) 3. สวนส าหรบ Operation
• ชนดของ Operation เหมอนกบ Attribute
• ชอของ Operation
• พารามเตอร ประกอบดวย ชอพารามเตอร : ประเภทพารามเตอร
• ประเภทของคาทสงคน (Return Type) ซงจะเขยนตามหลง :
อาจเปน Primitive Data Type หรออาจเปนคลาสอน ๆ กได
38
UML : Class Diagram สญลกษณ UML แสดง Class (ตอ) 3. สวนส าหรบ Operation
ตวอยาง
Car
- number of cars : integer
- data:CarData = “Unspecified”
- speed : Integer = 0
- direction : Direction
+ drive (speed: Integer, direction:Direction)
+ getData(): CarData
39
Classes
Window
display ()
size: Areavisibility: Boolean
hide ()
Window
Window
+default-size: Rectangle#maximum-size: Rectangle
+create ()
+display ()
+size: Area = (100,100)#visibility: Boolean = invisible
+hide ()
-xptr: XWindow*
-attachXWindow(xwin:Xwindow*)
{abstract,author=Joe,status=tested}
40
UML : Class Diagram ความสมพนธระหวางคลาส (Relationship)
ม 3 รปแบบ
1. Dependency คอความสมพนธแบบพงพง ความสมพนธแบบนเกดขนเมอการเปลยนแปลงทเกดขนกบคลาสทถกพงพง (Independent Class) จะสงผลตอคลาสทพงพง(Dependent Class) การโมเดลความสมพนธโดยวาดเสนตรงแบบประทมหวลกศร เปนเสนโปรงชจากซบคลาสทพงพงไปยงคลาสทถกพงพง ดตวอยางจากรป Dependent Class อาจเปนคาใชจาย สวน Independent Class อาจเปนคลาสงบประมาณ
Independent Class Dependent Class
41
UML : Class Diagram ความสมพนธระหวางคลาส (Relationship)
2. Generalization คอความสมพนธระหวางซปเปอรคลาสและซบคลาสนนเอง การโมเดลความสมพนธโดยการวาดเสนตรงทบทมหวลกศรเปนรปสามเหลยมโปรงชจากซบคลาสไปยงซเปอรคลาส ดงรป
Shape
Polygon Ellipse Circle
42
Generalization Shape
SplineEllipsePolygon
Shape
SplineEllipsePolygon
Shared Target Style
Separate Target Style
. . .
. . .
43
UML : Class Diagram ความสมพนธระหวางคลาส (Relationship) 3. Association เปนความสมพนธอกชนดหนงระหวางคลาสซงแบงไดดงน
3.1 Normal Association เปนโมเดลทซบซอน 2 ทศทาง
3.2 Aggregation เนนความสมพนธในแงการรวมกนหรอประกอบกน
3.1 Normal Association
โมเดลเชงซบซอน มความสมพนธแบบ 2 ทศทาง และก าหนดปรมาณของคลาสหรอ Object เรยกวา Multiplicity ดงรป
PERSON CAR OWNS 1..* 0..* IS OWN BY
44
UML : Class Diagram
3.2 Aggregation 3.2.1 Normal Aggregation แสดงดวยเสนตรงทบโยงระหวางคลาสโดยมสญลกษณขาวหลามตดตดอยระหวางปลายเสนความสมพนธกบคลาสทใหญกวา Team Person แตละทมประกอบดวยสมาชกหลายคนในทางกลบกน แตละคนอาจสงกดอยมากกวาหนงทม
* *
45
UML : Class Diagram
3.2.2 Composition เนนทคลาสทเปนองคประกอบจะเปนสวนหนงของคลาสทใหญกวา และเมอคลาสใหญกวาถกท าลาย คลาสทเปนองคประกอบกจะถกท าลายไปดวย เชน คลาสวโดวส จะประกอบไปดวยคลาสปม คลาสเมน เปนตน ซงคลาสเหลานน จะอาศยอยในวนโดวสทงหมด และเมอวนโดวสถกปดลงปม เมน กจะหายไปพรอม ๆ กนดวย
Window
Menu
Button
Text *
*
*
46
Composition Window
scrollbar [2]: Slidertitle: Headerbody: Panel
Window
scrollbar title body
Header Panel
21 1
Slider
111
47
UML : Class Diagram
Package เปนระบบยอย (Subsystem) เปนการจดกลมของคลาสหรอComponent
สญลกษณ เปน สเหลยมมมฉากทไมก าหนดขนาดและรปสเหลยมเลก(แทบ, Tab) ซอนอยทมมบนดานซายสด พรอมกบชอPackage
Department Package
48
Sequence Diagram
บอกวาใน Use Case นน วตถแตละตวจะตดตอสอสารกนอยางไร มขนตอนท างานอยางไร โดยจะเนนไปทแกนเวลาเปนส าคญ ถาเวลาเปลยน ขนตอนการท างานจะเปลยน โดยม Actor เปนผกระท าเรมตน
Customer
:Customer :Printer Server
:Printer :Queue
Print(file) Print(file) Printer free
Printer busy Store (file)
49
Activity Diagram
แสดงขนตอนการท างานของ Use Case แตมนจะเปลยนสถานะตามกระบวนการท างานคลายกบ Flowchart
ขอด คอ สามารถแสดงถงการท างานในวตถนน ๆ อยางละเอยดคลาย Flowchart และมการแบงแยกหมวดหมงานตาม Object
50
Activity Diagram
Customer Sales Stockroom
Request Service
Pay Take Order
Fill Order
Delliver Order Collect Order
52
Decision point and merge ( ) are inherited
from state machines.
For modeling conventional flow chart
decisions.
Coordinating Steps
Calculate
Cost
Charge
Account
Get
Authorization
[cost < $50]
[cost >= $50]
53
Activity Diagram Modeling Tips
Request Return
Get Return Number
Ship Item
Item [returned]
Receive Item
Restock Item
Credit Account
Item [available]
Customer Telesales Warehouse Accounting From UML
User Guide:
54
งานบคคลงานบณฑตศกษา งานหองสมด
รบรหสประจ าตวผานทางบารโคด
คนหาขอมลนกศกษา และสถานะ จากฐานขอมล รบรหสประจ าตวผานทางบารโคด
[รหสบารโคด][รหสบารโคด]
คนหาขอมลอาจารยและเจาหนาท จากฐานขอมล
คนหาสถานะอาจารยและเจาหนาท
[ชอ-สกล และ สถานะนกศกษา] [ชอ-สกล อาจารยและเจาหนาท]
[สถานะการเปนอาจารยและเจาหนาท]
นกศกษาระดบปรญญาตรจะใชการน าบตรนกศกษา และ ใบลงทะเบยนมายนยนในการยมครงแรกของแตละภาคการศกษาหลงจากนนใชบตรนกศกษาในการยนยนสถานะเพยงอยางเดยว
Activity Diagram ของการตรวจสอบผใชบรการ
Top Related