Download presentation
Presentation is loading. Please wait.
1
Class and Object Diagrams
2
Class diagram – basic syntax
Association name Class name Class name Attributes Methods Component This is a superclass aggregation Aggregate Class name specialization Class name This is a subclass Attributes Methods comments C-S 446/546
3
Class Diagram - semantics
A class icon must have a class name. Optionally, it can have attributes and/or methods. Attributes and methods are strings and will not be validated by the modeling tools. Attributes can be specified by their names or by <name : type> pairs. Methods can be specified by their names or with partial signatures or with complete signatures. C-S 446/546
4
Class Diagram – basic syntax (continued)
Comments can be included in any diagram with a rectangle folded at right top corner The dotted line from the comment is important to indicate which portion of the diagram is explained by the comment Suggestion For validation purposes, when showing aggregation relationship, the aggregate (the one near the diamond edge) must include an attribute whose type is the component class C-S 446/546
5
Details of a class icon Account - Account number : Integer
Initial value - Account number : Integer - Balance : Real - Overdraft : Boolean = true + GetAccountNumber () : Integer # UpdateBalance (sign : Sign, amt : Integer) ~ ReturnBalance () : Real ChangeOverdraft () + public private # protected ~ visible within the package C-S 446/546
6
Another view of the same class
Account Private: Account number : Integer Balance : Real Overdraft : Boolean = true Initial value Public: GetAccountNumber () : Integer Protected: UpdateBalance (sign : Sign, amt : Integer) Package: ReturnBalance () : Real Private: ChangeOverdraft () C-S 446/546
7
{abstract, author = Kasi, last modified = Oct 2002}
An abstract class Polygon {abstract, author = Kasi, last modified = Oct 2002} <<constructor>> + Polygon(List of Vertex vertices) <<query>> #area () : Real C-S 446/546
8
ATM – class diagram Account Accounts Database Login Accounts Database
- Account# : Integer - UserID : Integer - Balance : Double - Accounts : Account[] + addAccount (account) + deleteAccount (acct#) + searchAccount (acct#) + updateAccount (acct#) + getBalance() : double + verifyUser (actnum, uid) : Boolean + deposit (amt) + withdraw (amt) 1 uses Login Accounts Database 1 - Accounts : Login Account[] Login Account + addAccount (account) + deleteAccount (uid) + searchAccount (uid) + updateAccount (uid) - UserID : Integer - Password : String + changePassword (str) C-S 446/546
9
Object Diagram act : Account : Account act : Account
UserID = 120 Balance = 0 act : Account Various representations of an account object C-S 446/546
10
Item Library Book Periodical BorrowItem Borrower C-S 446/546
Title : String CallNumber : String Books : Book[] Loans : BorrowItem[] Periodicals : Periodical[] Users : Borrower[] Book Periodical addBook : (b : Book) addPeriodical (p : Periodical) searchBook (callno : String) : Book searchPeriodical (callNo : String) : Periodical addUser (u : Borrower) deleteUser (id : String) searchUser (id : String) : Borrower loanItem (u : Borrower, b : Book) addBorrowItem (bi : BorrowItem) deleteBorrowItem (callNo : String) calculateFine() payFine (u : Borrower) Author : String YearOfPublication : Integer Volume : String Issue : String Year : Integer BorrowItem BorrowerID : String DueDate : Date Borrower ID : String BooksBorrowed : BorrowItem[] Fine : Double C-S 446/546
11
Object Diagram book : Book : Book book : Book
Title : “Specification of Software Systems” Author: “VS Alagar and K Periyasamy” CallNumber : “QA W321” YearOfPublication : 1998 book : Book Various representations of a book object C-S 446/546
12
Association –syntax uses Account User uses Corporate Account
Association label Direction of association uses customer Account User 1 n -Account number -Balance -Overdraft Manager 1 cardinality +Get accountID () +Update balance() +Return balance() Role names {xor} Unary association uses Corporate Account n C-S 446/546
13
Association - Semantics
Every association is expected to be labeled UML does not require a name for an association Direction of an association, cardinality, role name are all optional For unary associations, it is better to include role names Representations of cardinality 0, 1, * (zero or more), n..m (values in the range between n and m both inclusive) C-S 446/546
14
Association – Semantics (continued)
A constraint may be [optionally] placed between two associations See the example in the previous slide that asserts an Exclusive OR relationship between the associations When a subclass specializes a superclass, it also inherits all associations between the superclass and other classes In the previous example, the association “uses” between “User” and “Account” is also inherited by the pair “User” and “Corporate Account” C-S 446/546
15
Association with qualifiers
uses Account User 1 n -Account number -Balance -Overdraft Account number +Get accountID () +Update balance() +Return balance() Qualifier attribute Qualifier Corporate Account C-S 446/546
16
Association - Qualifiers
Qualifiers can be attached to a “one-to-many” association It is rectangle attached to the “many” end of the association A qualifier is a collection of variables whose values uniquely identify an instance at the “many” end of the association In the example, an account number uniquely identifies an account in a collection of accounts Qualifier is part of the association C-S 446/546
17
Association Class User Account Job Employee Salary Transaction
C-S 446/546
18
Association Class - semantics
A piece of information that belongs to both classes in an association is put into a separate class called “association class” Association class is a dependent class that depends on the other two classes in the association An association class cannot exist independently An object of an association class must refer to objects of the other two classes in the association Example: A “Transaction” object depends on a “User” object and on an “Account” object. C-S 446/546
19
Shared Aggregation An aggregation relationship in which the component can be shared by classes/objects outside the aggregation Team Person Family Person object is shared by both Team and Family objects Shared aggregation is indicated by a hallow diamond Caution: Changes made to a component object will affect all the aggregates that include the component. C-S 446/546
20
Composite Aggregation
An aggregation relationship in which the component is an exclusive part of the aggregate; hence, not shared. Wing 2 1 Air Plane 1 2 Engine Composite aggregation is indicated by a filled diamond C-S 446/546
21
Advanced Specialization
Person Gender {complete, disjoint} Sports activity {incomplete, overlapping} Boy Girl Swimmer Runner These optional domain words make the relationships easier to understand. C-S 446/546
22
Exercise 1 Extend the library class diagram to include the following:
Borrowers can now reserve books. No periodical can be reserved. A book can be reserved only when a borrower wants to borrow that book but it is loaned to another borrower need some status variable for books. C-S 446/546
23
Exercise 2 Redesign the classes in Exercise 1 so that the classes “Borrow Item” and “Reservation” are now designed as Association classes. C-S 446/546
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.