Professional Documents
Culture Documents
Week 2
Week 2
EL
• Factoring use cases ...
• Text description ...
PT
• Design of Use Case model from a
N
given text description ...
1
• Use case name should begin with a verb. Style Notes
• While use cases do not explicitly imply timing: (Ambler, 2005)
– Order use cases from top to bottom to imply timing -- it improves
readability.
• The primary actors should appear in the left.
EL
• Actors are associated with one or more use cases.
• Do not use arrows on the actor-use case relationship.
PT
• To initiate scheduled events include an actor called
“calendar”
• Do not show actors interacting with each other.
N
• <<include>> and <<extend>> should rarely nest more
than 2 levels deep.
2
Effective Use Case
• Use cases should be named and organized
Modelling
from the perspective of the users.
EL
much higher view as possible.
– Can be refined and detailed further.
PT
• Use case diagrams represent functionality:
N
– Should focus on the "what" and not the "how".
3
Is it OK?
EL
be avoided!
PT
N
4
Use Case Packaging
Accounts
EL
Query balance
Balance sheet
PT
Receive Make
grant payments
N
5
Which is more acceptable?
EL
PT
N
6
• HAS will be used by an instructor to: Quiz: Home Assignment
– Distribute homework assignments, System - Use Case Model
– Review students’ solutions,
– Distribute suggested solution,
– Assign a grade to each assignment.
EL
• Students can:
– Download assignments
PT
– Submit assignment solutions
• System:
N
– Automatically reminds the students a day before
an assignment is due.
7
Remind Quiz: Solution 1
Student
(Inferior)
Calendar Distribute Get
Assignments Assignment
EL
Submit
<<Extends>>
Post Solutions Assignment
PT
Student
Distribute Get
Grade Solution
Instructor
N
Get Grade
8
Quiz: Alternate
Distribute
Assignments (Better) Solution
Post Solutions
EL
Student
Distribute
PT
Grade
Instructor
Submit
Assignment
Calendar
NRemind
Student
9
Class Diagram
EL
PT
N
10
Class: A
Template for object creation:
Fundamental
− Instantiated into objects Object-Oriented
Concept
Examples: Employees, Books, etc.
EL
PT
Sometimes not intended to produce
instances:
N
− Abstract classes
11
• Entities with common features Class Window
are made into a class. Diagram
size: Size
• Represented as solid outline rectangle visibility: boolean
with compartments.
EL
display()
hide()
• Compartments for name, attributes,
PT
and operations. Window
• Attribute and operation compartments
N
are optional ... used depending on the
purpose of a diagram.
12
UML Class Representation
• A class represents a set of objects having similar attributes,
operations, relationships and behavior.
Class Name
EL
Window
A class can
PT
size: Size implicitly
Attributes have a few
visibility: boolean association
attributes
Operations
N
display()
hide()
13
Different representations of the LibraryMember class
LibraryMember LibraryMember LibraryMember
EL
Phone Number returnBook( );
E-Mail Address findMembershipDetails( );
Membership Admission Date
Membership Expiry Date
PT
Books Issued
issueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
findMembershipDetails( );
N
14
Class Attribute Examples
Java Syntax UML Syntax
EL
Date birthday Birthday:Date
PT
Public int duration = 100 +duration:int = 100
Private Student
students[0..MAX_Size]
N-Students[0..MAX_Size]:Student
15
Visibilty Java Syntax UML Syntax Visibility
Syntax in
public public + UML
EL
protected protected #
PT
package ~
private N
private -
16
Methods are the operations supported by Methods
an object: vs.
Messages
− Means for manipulating the data of an object.
EL
− Invoked by sending a message (method call).
PT
− Examples:calculate_salary(), issue-book(),
N
getMemberDetails(), etc.
17
Method Examples
EL
void move(int dx, int dy) ~move(int dx,int dy)
PT
public int getSize() +int getSize()
N
18
Are Methods and Messages Synonyms?
• No
• Message was the original concept in
EL
object-orientation…
PT
• Methods are the later simplifications…
N
• Sometimes used as synonyms
19
Are Methods and Operations Synonyms?
• No
• An operation can be implemented by
EL
multiple methods.
– Known as polymorphism
PT
– In the absence of polymorphism-–the
N
two terms are used as synonyms.
20
What are the Different
• Four types: Types of Relationships
Among Classes?
– Inheritance
EL
– Association
PT
– Aggregation/Composition
– Dependency
N
21
• Allows to define a new class (derived Inheritance
class) by extending an existing class
(base class).
LibraryMember Base Class
EL
–Represents generalization-
specialization relation. Derived
PT
Faculty Students Staff
Classes
22
Inheritance One More Example
Library “A Student ISA Library Member”
Member
EL
“A Faculty ISA Library Member”
PT
Stdent Faculty
N
23
Inheritance: Semantics
• Lets a subclass LibraryMember Base Class
inherit
attributes and
EL
Derived
methods from Faculty Students Staff
Classes
PT
a base class.
N
UnderGrad PostGrad Research
24
LibraryMember Base Class LibraryMember Base Class
Multiple
Inheritance
EL
Derived
Faculty Students Staff Faculty Students Staff
Classes
PT
Multiple
Inheritance
25
Inheritance Implementation in Java
Inheritance is declared using the "extends" keyword
Even when no inheritance defined, the class implicitly extends a class called Object.
EL
private Date dob; - name: String
- dob: Date
...
}
PT
class Employee extends Person{
private int employeeID;
private int salary;
...
N
private Date startDate;
Employee
- employeeID: int
- salary: int
} - startDate: Date
26
Rectangle myRectangle = new Rectangle(5, 3); Objects
Box myBox = new Box(6, 5, 4); myRectangle
and myBox
length 6.0 Rectangle
EL
length 5.0
myRectangle myBox width 5.0 Box
PT
width 3.0
Object
Reference
N height 4.0
27
More
Mammal Quadruped Generalization
Examples…
EL
Feline Lizard
PT
Tiger
N
Lion Puma
28
Any problems? Wrong
Car Generalization -
attributes
operations
--
violates “is a” or
“is a kind of”
EL
Engine Door
heuristic
Chassis
PT
attributes attributes attributes
operations operations operations
N
29
Library Inheritance Example
Book
issuable reference
EL
PT
Issuable Reference
Issuable Reference
Single Volume Single Volume
BookSet BookSet
Book Book
N
Discriminator: allows one to group subclasses into
clusters that correspond to a semantic category.
30
Inheritance Pitfalls
• Inheritance certainly promotes reuse.
• Indiscriminate use can result in poor
EL
quality programs.
PT
• Base class attributes and methods
visible in derived class…
N
– Leads to tight coupling
31
• How implemented in program? Association
Relationship
• Enables objects to communicate with each other:
–One object must “know” the ID of the
EL
corresponding object in the association.
PT
• Usually binary:
N
–But in general can be n-ary.
32
Association – An Example
• In a home theatre system,
– A TV object is associated with a VCR object
EL
• It may receive a signal from the VCR
PT
– VCR may be associated with remote
• It may receive a command to record
Remote
1
N
1
VCR
1 1
commands Connected to TV
33
tax_file 1-1 Association
Rakesh Shukla 760901-1234
– example
V. Ramesh
EL
691205-5678
Keshab Parhi
PT
People Tax_files
People 1 N
Associated
1
Tax_files
with
34
motherOf
Multiple
motherOf
Bhim Association –
Kunti Yudhistir
example
EL
motherOf
Arjun
PT
Woman Person
Woman 1
N
Mother of
*
Person
35
role B Association
Class A role A Class B
UML Syntax
• A Person works for a Company.
Role
EL
PT
Person employee employer Company
works for
N
Association Name
36
Multiplicity: The number of objects Association -
from one class that relate with a single More Examples
object in an associated class.
EL
Library Member
1 borrowed by *..5 Book
PT
Lion
* N
eats
* Human
37
Navigability
EL
opens 0..5
Key * Door
PT
N
38
• A teacher teaches 1 to 3 courses (subjects) Association
• Each course is taught by only one teacher. – Quiz 1
• A student can take between 1 to 5 courses.
A course can have 10 to 300 students. Draw the class diagram.
EL
•
1 teaches 1..3
Teacher Course
PT
1..5
Students
10..300
N
39
• A Student can take up to five Courses. Quiz 2: Draw
• A student needs to enroll in at least one Class Diagram
course.
• Up to 300 students can enroll in a course.
EL
• An offered subject in a semester should have
PT
at least 10 registered students.
Student credits
10..300
N hasEnrolmentOf
Enrols in 1..5
Course
40
Student credits
10..300
hasEnrolmentOf
Enrols in 1..5
Course
A Identify as
Correct or
Wrong
Student credits hasEnrolmentOf
Enrols in
Course B
EL
10..300 1..5
PT
Student credits hasEnrolmentOf Course
10..300 Enrols in 1..5
Student credits
N
hasEnrolmentOf
Course D
10..300 Enrols in 1..5
41
Quiz: Read the Diagram
1..2 teaches 0..3
Teacher Course
EL
PT
opens 0..5
* Door
Key
N
42
• A link: Association
– An instance of an association and Link
– Exists between two or more objects
– Dynamically created and destroyed as
EL
the run of a system proceeds
PT
• For example:
– An employee joins an organization.
N
– Leaves that organization and joins a new
organization.
43
• A class can be associated with itself Unary
(unary association). Association
–Give an example?
EL
• An arrowhead used along with name:
–Indicates direction of association.
PT
• Multiplicity (association cardinality)
N
indicates # of instances taking part in
the association.
44
Uniary Association: Example 1
Supervises
1
EL
Boss
Person *Employee
PT
N
45
Self Association:
Example 2
Computer Network
Connects to
EL
*
PT
Computer *
N
46
Computer
Node1 Node2 Node3 Network:
Object
Node4
Diagram
EL
Node5
PT
Node6 N
Node7 Node8
47
Self Association:
Connected to Example 3
EL
next
LinkedListNode
PT
previous
N
48
Reflexive
Course Association:
* Example 4
EL
PT
*
N
has pre-requisite of
49