What is UML?
UML ุงุฎุชุตุงุฑ ูู Unified Modeling Language: ูุบุฉ ุฑุณูู ูุฉ ู ุนูุงุฑูุฉ ููู ุฐุฌุฉ ุจุฑู ุฌูุงุช OO.
- ุทููุฑูุง Rumbaugh, Booch, Jacobsonุ ูุงูู ุนุฑูููู ุจุงุณู Three Amigos.
- ุฃุณูุณูุง Rational Software Corporationุ ูุงููู ุงุดุชุฑุชูุง IBM ุจุนุฏ ูุฏู.
- ูู 1997ุ ุจุฏุฃุช ู ูุธู ุฉ Object Management Group (OMG) ุนู ููุฉ standardization.
๐๏ธ Static View
- Class diagrams โ describe classes & relationships.
- Component diagrams
- Deployment diagrams
๐ฌ Dynamic View
- Sequence diagrams โ object interactions.
- Communication diagrams
- State diagrams (internal behavior)
- Activity diagrams
Class Diagram Essentials
5 ุฑู ูุฒ ุฃุณุงุณูุฉ: Classes ยท Attributes ยท Operations ยท Associations ยท Generalizations.
width
resize()
โ width: int
+ resize(int, int)
- ุงุณู ุงูู class ููุท (ู ุณุชูู ู ุฌุฑุฏ).
- Attributes + Operations (ู ุณุชูู ู ุชูุณุท).
- Full signature ู
ุน ุงูู visibility (
+= public,โ= private) ูุงูู types (ู ููุฏ ููู implementation).
operationName(parameterName: parameterType, ...): returnType
ู
ุซุงู: resize(width: int, height: int): void
ุฑุณูู ุงุช Class diagram ุจุชุฎุชูู ุญุณุจ ุงูู ุฑุญูุฉ:
- Domain Analysis โ ู ุณุชูู ุนุงููุ ูู ูุงููู business (ู ู ุบูุฑ methodsุ ุบุงูุจุงู attributes ุจุณ).
- Requirements Specification โ ุจุชุถูู ุงูู operations ุงููู ุธูุฑุช ู ู ุงูู use cases.
- Implementation โ ุดุจู ุฎุฑูุทุฉ ู ุจุงุดุฑุฉ ููููุฏุ ููููุง visibility ู types ู library classes.
ุจุชุชุทูุฑ ุจุดูู iterative ู ุน ุงูููุช.
Associations & Multiplicity
ุงูู Associations ุจุชุฑุจุท ุงูู classes ุจุจุนุถูุง. ูุงูู Multiplicity ุจุชูุถุญ ูุงู instance ู ุณู ูุญ ู ู ูู side.
- A company has many employees (*).
- An employee works only for 1 company.
- A company can have zero employees (e.g. shell company).
- An employee must work for a company (multiplicity 1, not 0..1).
- An assistant can work for many managers (1..*).
- A manager can have many (or 0) assistants.
- Question: is it possible for assistant to have zero managers temporarily?
โ Avoid this
โ Do this
birthdate
address
ูู ุนูุงูุฉ ุงูู 1:1 ุฅูุฒุงู ูุฉ ุฏุงูู ุงูุ ุฎููููุง attribute ุฏุงุฎู ููุณ ุงูู class ุจุฏู ู ุง ุชุนู ู relation ู ููุตูุฉ.
Special Associations
Association classes ยท Reflexive associations ยท Directionality.
ุฃุญูุงูุงู ุจูููู ููู attribute ูุฎุต ุงูุนูุงูุฉ ุจูู 2 classesุ ู ุด ุงูู classes ููุณูุง.
ู ุซุงู: grade ุงูุทุงูุจ ูู course. ุงูุฏุฑุฌุฉ ู ุด property ููู student ูุฃูู ุนูุฏู ุฏุฑุฌุงุช ูุชูุฑุ ูู ุด property ููู course ูุฃูู ููู ุทูุงุจ ูุชูุฑ. ูู property ููู registration.
ุฏู ู ูุงูุฆ ูู:
ุงูู Class ู
ู
ูู ุชุฑุจุท ููุณูุง ุจููุณูุง. ู
ุซุงู: Course:
โฉ prerequisite (* to *)
โฉ isMutuallyExclusiveWith (* to *)
ู ุซุงู ุนูู ุงูู instances:
CS251 (prerequisite) โ CS352 (successor)
ุงูู Associations ุงูุชุฑุงุถูุงู bi-directional. ุชูุฏุฑ ุชุญุฏุฏ ุงูู direction ุจุณูู ุนูุฏ ุงูู end.
ูุนูู Day ุจูุนุฑู ุงูู Notes ุงููู ุชุฎุตูุ ููู ุงูู Note ู
ุง ูุนุฑูุด ุงูู Day ุจุชุงุนู.
Generalization (Inheritance)
ุงูู Superclass ูู ุงูุฃุจุ ูุงูู Subclasses ุชุฑุซ ู ูู. ุณูู ุงูู open triangle ุจูุดูุฑ ูุงุญูุฉ ุงูู superclass.
ุงูู Subclasses ุจุชุฑุซ ุงูู attributes ูุงูู operations ู ู ุงูู superclass.
Generalization Set = ุชุฌู ูุน ููู subclasses ุจูุงุกู ุนูู discriminator (ู ุนูุงุฑ ุงูุชุฎุตุต).
ุงูู Animals ู ู ูู ูุชูุณู ูุง ุจุฃูุชุฑ ู ู ู ุนูุงุฑ: habitat (aquatic/land) ู typeOfFood (carnivore/herbivore). ุนูุฏูุง ุญููู:
Option 1: Higher-level Generalization
Animal โ AquaticAnimal โ AquaticCarnivore + AquaticHerbivoreุ ูููุณ ุงูููุฑุฉ ู ุน Land.
โ ๏ธ ุจูุนู ู classes ูุชูุฑุฉ (4 leaves).
Option 2: Multiple Inheritance
ุงูู AquaticCarnivore ุชุนู ู inherits from both ู ู AquaticAnimal ู Carnivore.
โ ๏ธ ู ุด ูู ุงููุบุงุช ุจุชุฏุนู ูุง (Java ูุงุ C++ ูุฏุนู ูุง).
ูู ุงูู instance ู ู ูู ูุชุบูุฑ ู ู type ูู type ุชุงููุ ู ุง ุชุณุชุฎุฏู ุด inheritance. ุงุณุชุฎุฏู attribute ุจุฏุงููุง.
โ Avoid
ุทุงูุจ ู ู ูู ูุชุญูู ู ู part-time ูู full-time โ ู ุดููุฉ
โ Do
attendance: enum
ุงูู attendance ูู attribute ูุชุบูุฑ ุจุณูููุฉ
Aggregation vs Composition โญ
ุฏู ุนูุงูุงุช part-whole. ุงููุฑู ุงูุฃุณุงุณู ุจูููู : ูู ุงูู part ุชูุฏุฑ ุชุนูุด ุจุฏูู ุงูู wholeุ
ุงูู Aggregation ุนูุงูุฉ part-wholeุ ููู ุงูู parts ุชูุฏุฑ ุชุนูุด ู ุณุชููุฉ ุนู ุงูู whole.
- ุงูู Vehicle parts ู ู ูู ุชูุฌู ู ู cars ู ุฎุชููุฉ ูุชูุณุชุฎุฏู ุชุงูู (reused).
- ูู ุงูู Vehicle ุงุชุฏู ุฑุ ุงูู parts ู ู ูู ุชุณุชุฎุฏู ูู Vehicle ุชุงูู.
โ When to use Aggregation:
- ุชูุฏุฑ ุชููู ุฅู ุงูู parts are part of ุงูู aggregateุ ุฃู ุฅู ุงูู aggregate is composed of ุงูู parts.
- ูู ุง ุดูุก ูู ูู ุฃู ูุชุญูู ูู ุงูู aggregateุ ููู ุบุงูุจุงู ูู ูู ุฃู ูุชุญูู ูู ุงูู parts ูู ุงู.
ุงูู Composition ูู strong aggregation. ูู ุงูู aggregate ุงุชุฏู ุฑุ ุงูู parts ุงุชุฏู ุฑุช ู ุนุงู. ุงูู part ู ุง ุชูุฏุฑุด ุชุนูุด ุจุฏูู ุงูู whole.
- ุงูู Rooms ู ุง ุชูุฏุฑุด ุชูุฌุฏ ุจุฏูู ุงูู Building.
- ูู ุงูู Building ุงุชูุฏุ ุงูู Rooms ุฑุงุญุช ู ุนุงู.
| Aspect | Aggregation โ | Composition โ |
|---|---|---|
| Symbol | Open (hollow) diamond | Filled (solid) diamond |
| Part lifecycle | Independent | Tied to whole |
| If whole destroyed | Parts survive | Parts destroyed |
| Part can be reused | Yes (in other wholes) | No (one whole only) |
| Example | Vehicle - VehiclePart ยท Country - Region | Building - Room ยท Book - Chapter (if Chapter can't exist alone) |
As Composition
city
country
As Attribute
ุฃุจุณุท ูู ุงูู Address ู ุง ุนูุฏูุงุด complexity ูุจูุฑุฉ
Mechanism: ุงูู operation ูู ุงูู aggregate ุจุชุชููุฐ ุจุฃู ุงูู aggregate ูุนู ู perform ูููุณ ุงูู operation ุนูู ุงูู parts ุจุชุงุนุชู.
ู
ุซุงู: Polygon.draw() ุจุชุชููุฐ ุจุฃู ุงูู Polygon ูุทูุจ ู
ู ูู LineSegment ุฅููุง ุชุนู
ู draw().
ูุนูุณูุงู: ุงูู properties ุงูุฎุงุตุฉ ุจุงูู parts ู ู ูู ุชูุชุดุฑ ููู aggregate.
Object Diagrams
ุงูู Object ูู instance ู ู class. ูุงูู Link ูู instance ู ู association.
| Class Diagram | Object Diagram | |
|---|---|---|
| Shows | Types and relationships | Specific instances at runtime |
| Naming | Employee | Pat: Employee (instance:class) |
| Underline? | No | Yes (object name underlined) |
| Generalizations | โ Shown | โ Don't appear in object diagrams |
| Associations | Class-level | Become links between objects |
- Pat ู Wayne instances ู ู Employee.
- OOCorp instance ู ู Company.
- ุงูู Links ุจุชุนูุณ ุนูุงูุฉ worksFor ุงููู ู ูุฌูุฏุฉ ูู ุงูู class diagram.
Full Example: Problem Report Tool
ุฃุฏุงุฉ CASE tool ูุชุฎุฒูู ูุชุชุจุน ุงูู problem reports. ุฏู ู ุซุงู ุดุงู ู ููู ุงูู relations.
- Employees are either developers or managers (generalization).
- Each developer has a manager (1 manager per developer).
- Project assigned a manager + a number of developers.
- Developer/manager may be assigned to multiple projects or to none (0..*).
- Project consists of artifacts (domain analysis, SRS, code, test cases...) โ aggregation.
- Problem reports can be made on any artifact.
- Each report contains: problem description and status.
- Each problem can be assigned to someone by the project manager.
- Report has history entries (action/update logs) โ aggregation.
- A special kind of reports: Code/Bug Reports with extra info (location, circumstances, failed tests) โ generalization.
โโโโโโโโโโโโ
โ Employee โ (name: String)
โโโโโโณโโโโโโ
โ
โโโโโโโดโโโโโโโโโโโ
โโโโโดโโโโ โโโโโโโดโโโโโ
โManagerโ โDeveloper โ
โโโโโฌโโโโ โโโโโโฌโโโโโโ
โ โ * managed by 1
โ 1 โโโโโโโโโโโโโโโโโโโ
โ responsibleFor โ Manager
โ 0..* โ * assigned 0..*
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Problem Rep. โ โ Project โ (name)
โ + status โ โโโโโโโโโโโโโโโ โ aggregation
โ + desc โ โ 1
โ โ โ 0..*
โโโโณโโโโโโโโโโโโ โโโโโโโโโโโโโโ
โ โ Artifact โ โโ associated 0..n โโโ Problem Report (label: "About")
โโโโดโโโโโโโโโโโ โ +name โ
โ CodeBugRep. โ โ +status โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโ
Problem Report โโโโโ 0..n โโโโ History Entry (when: Date, whatDone: String)
"History Log"
1. Generalization โ ุงูู Manager ูุงูู Developer ุจูุฑุซูุง ู ู Employeeุ ูุงูู CodeBugReport ุจูุฑุซ ู ู Problem Report.
2. Associations โ ู ุซู Developer managedBy Managerุ ู Employee assignedTo Projectุ ู Artifact About Problem Report.
3. Aggregation โ Project โ Artifactุ ู Problem Report โ History Entry.
4. Multiplicities โ ุฒู: 1ุ *ุ 0..*ุ 1..*ุ 0..n.
5. Labels โ Managed Byุ Assigned Toุ Responsible Forุ Aboutุ History Log.
13 Slide Exercises โ Practice
ุฏู ุงูุชู ุงุฑูู ุงููู ุฏ. ุงูุฑู ูู ุญุงุทุทูุง ูู ุงูุณูุงูุฏุฒ. ูุงุฒู ุชุญููู ูููู ุ ูุฃู ูู ุชู ุฑูู ุจูุฎุชุจุฑ concept ู ุฎุชูู.
Shape โ Triangle, Square (open-triangle generalization arrow).
Class diagram: Account [1] โโ [0..n] Client +owner
- Ex 2: What relation? โ Simple Association with multiplicity.
- Ex 3: What's true?
- A client can own multiple accounts? True (0..n on client side from account's perspective is the inverse โ actually account is 1 to many clients here meaning 1 account has 0..n owners; the question is open to interpretation, but conventional answer follows the diagram).
- An account can be used to access its client? True (bidirectional by default).
- A client can be used to access its account? True.
- Ex 4: What's true?
- An account can have multiple owners? True (0..n on client side).
- No account can exist without a client? Depends โ if 0..n includes 0, account can exist without clients.
- A client must have an account? True if multiplicity is 1 on account side.
- It shows a composition relation? โ True (filled diamond).
- A building may have no rooms? โ False if multiplicity is 1..* (depends on diagram).
- A room may exist without a building? โ False โ composition means parts die with whole.
- It shows a composition relation? โ False (no diamond shown).
- An employee may have no address? โ False if multiplicity is 1 (mandatory).
- An address may exist without an employee? โ True if it's a plain association.
Part 1: Manager [1] managedBy [0..*] Developer (subclasses of Employee).
- Employee can be Manager and Developer at the same time? โ False (in single inheritance, subclasses are disjoint).
- Manager may have no developers assigned? โ True (0..* includes 0).
- Developer has one and only one manager? โ True (multiplicity 1).
Part 2: Employee [1..*] assignedTo [0..*] Project.
- Project has at least one employee? โ True (1..*).
- Every developer must be assigned to a project? โ False (0..* on project side means dev can have zero projects).
- Manager may have no projects? โ True.
- A course may have any number of prerequisites or none? โ True (multiplicity *).
- A course may not be taken with any number of courses? โ False (it CAN be).
- A course may have an association relation with another course? โ True โ reflexive association.
ุงูู scenario: ุงูู Book ููู volumesุ ูุงูู volumes ูููุง chapters. ูุงูู Chapters can be sold alone ุญุชู ูู ุงูู book ู ุด ู ุชุงุญ.
- Fig 1 (Composition 1:* / 1:*) โ โ ุบูุท ูุฃู ุงูู composition ู ุนูุงูุง ุฅู ุงูู parts ู ุง ุชูุฏุฑุด ุชูุฌุฏ ููุญุฏูุง.
- Fig 2 (Composition 1..* / 1..*) โ โ ุบูุท ูููุณ ุงูุณุจุจ.
- Fig 3 (Aggregation 1..* / 1..*) โ โ ุตุญ ูุฃู ุงูู parts ู ู ูู ุชูุฌุฏ ู ุณุชููุฉ.
ุงูุฑุฃ ุงูู diagram ุจุฏูุฉ:
- CurrentEventDisplay can display both SpecialEvents and RegularEvents? โ True โ both inherit from Event, and Event is displayed.
- CurrentEventDisplay can display multiple events? โ True if multiplicity supports it.
- Schedule can contain an Announcement? โ False โ Schedule aggregates Event, not Announcement.
- UserInterface can display either events or announcements but not both? โ False โ different subclasses of UI handle different types.
- SpecialEvent should have at least one Date? Depends on multiplicity on Date association.
- An Announcement can have a Date? โ False โ Announcement doesn't connect to Date in the diagram.
Class diagram: Writer [*] โ [1] Document
ุงูู multiplicity ุนูู ูุงุญูุฉ ุงูู Writer ูู *ุ ูุนูู document ูุงุญุฏ ู ู ูู ูููู ูู writers ูุชูุฑ ุฃู ููุง ูุงุญุฏ.
- Figure I: 1 Writer โ 1 Document โ valid
- Figure II: 2 Writers โ 1 Document โ valid (matches * to 1)
- Figure III: 1 Writer โ 1 Document โ valid
- Fig 1 (Aggregation โ) โ โ wrong, body parts can't survive without person.
- Fig 2 (Composition โ) โ โ correct โ body parts die with person.
- Fig 3 (Generalization) โ โ very wrong, Head IS-NOT-A Person.
"Knowing that parts can be sold separately" โ Aggregation.
- Fig 1 (Aggregation โ) โ โ correct.
- Fig 2 (Composition โ) โ โ wrong, parts die with whole.
- Fig 3 (Generalization) โ โ very wrong, Engine IS-NOT-A Car.
Exam Question Bank โ Lecture 5
4 ุฃุณุฆูุฉ ุญููููุฉ ู ู ุงู ุชุญุงูุงุช ุงูู MCQ ุนูู Class Diagrams. ุงูู Question 2 ูู ูู ุงู ุชุญุงู (UML Modeling, 20 marks) ุจูุนุชู ุฏ ุนูู ุงูู concepts ุฏู.
Advertiser [1] โโ [*] Account. Which code properly implements it?
Code (a): Advertiser has
Set accounts, addAccount() adds & sets owner with null check. Account has setOwner() that calls addAccount if newOwner != null.
Code (b): Advertiser has single
Account account field. (Wrong โ should be Set.)
Code (c): Advertiser has Set; Account has
Set owners (multiple owners!). (Wrong โ should be single owner.)
1 to * ู
ุนูุงูุง: Advertiser ูุงุญุฏ โ Accounts ูุชูุฑ. ุงูููุฏ ุงูุตุญ:
- ุงูู Advertiser ููู
Set<Account> accounts(collection). - ุงูู Account ููู
Advertiser owner(single referenceุ ู ุด Set). addAccountูsetOwnerุจูุดุชุบููุง ู ุนุงู ููุญูุงุธ ุนูู ุงูู bidirectional integrity.
Account account (single) ูู Advertiser ุจุฏู Set. ุบูุท ูุฃู ูู Advertiser ูุงุฒู
ููุฏุฑ ูู
ุชูู multiple accounts. ยท
C โ ุฎูู ุงูู Account ููู Set ู
ู Advertisers (multiple owners). ุฏู many-to-manyุ ู
ุด 1-to-*.
class Order { OrderStatus status; ArrayList<OrderDetail> details; ... }
class OrderDetail { Product product; }
class Product { String code, name; float unitPrice; }
enum OrderStatus { OPEN, CLOSED; }
ArrayList<OrderDetail>= Order has many OrderDetails (multiplicity *).- Order owns OrderDetails completely (composition โ).
- OrderDetail has single Product reference (1:1 association).
- Order has OrderStatus enum.
ArrayList ู
ุนูุงูุง ุนูุงุตุฑ ู
ุชุนุฏุฏุฉ. ยท
C โ ุงูู Order ูู
ูู OrderDetails ูุฌุฒุก ู
ูู (composition)ุ ู
ุด ู
ุฌุฑุฏ association. ยท
D โ Many-to-many ุบูุทุ ูุฃู ุงูู OrderDetail ุจูุฎุต Order ูุงุญุฏ ููุท.
(a) Class A with self-association (regular line with arrowhead).
(b) Class A with self-loop (curve from one end to another, plain).
(c) Class A with self-loop showing generalization arrow (open triangle).
(d) Class A with self-loop showing aggregation diamond.
A extends A = infinite loop ู
ู ูุงุญูุฉ ุงูู
ุนูู. ุฏู ู
ุณุชุญูู ูู OO design.
Project [0..*] โโ [1..*] Employee. Which is true?1..*ุนูู ูุงุญูุฉ ุงูู Employee โ ูู project ูุงุฒู ูููู ุนูุฏู employee ูุงุญุฏ ุฃู ุฃูุชุฑ.0..*ุนูู ูุงุญูุฉ ุงูู Project โ ูู employee ู ู ูู ูููู ู ุฑุชุจุท ุจู 0 ุฃู ุฃูุชุฑ ู ู ุงูู ุดุงุฑูุน.
- Self-association: Course โ Course (prerequisite).
- Self-aggregation: Folder โ SubFolder.
- Self-composition: Tree โ SubTree.
Cheat Sheet
ูู ุงูุฑู ูุฒ ูุงูู ุตุทูุญุงุช ูุงูููุงุนุฏ ูู ุตูุญุฉ ูุงุญุฏุฉ.
๐จ UML Symbols
๐ข Multiplicity
๐ Relations Decision Tree
๐ UML 3 Amigos
โ ๏ธ Common Pitfalls
๐ฏ Reading Multiplicity
Rapid Revision
Flashcards ยท Common Mistakes ยท What the doctor loves to ask.
๐จ Common Mistakes
A [1] โ [*] B: ููู B ูุงุญุฏุ ููู A ูุงุญุฏ ุจุณ.โญ What Dr. El-Ramly Loves to Ask
- Code โ Class Diagram โ ุจูุฏู Java/C++ code ูุนููู ุชุฎุชุงุฑ ุงูู diagram ุงูุตุญุ ุฃู ุงูุนูุณ.
- Aggregation vs Composition โ ุจูุฏู scenario ู ุซู book ุฃู car ุฃู buildingุ ูุนููู ุชุญุฏุฏ ุงูู relation ุงูุตุญ.
- Which class diagram is wrong? โ ุงูู self-generalization ุฏุงูู ุงู ุบูุท.
- Multiplicity questions โ ุชูุณูุฑ diagram ู ุนุทู ู ุซู manager-developer ุฃู project-employee.
- Question 2 (UML Modeling) โ 20+ ู ุงุฑู ุนูู ุจูุงุก use case diagram + class diagram + sequence diagram + state diagram ููุธุงู ู ุนูู. ุฑูุฒ ุนููู ูุฃูู ุจูุชูุฑุฑ ูู ูู ุงู ุชุญุงู final.