Prof. R. Mall
Dept. of CSE, IIT, Kharagpur
Object-oriented concepts Object modelling using Unified Modelling Language (UML) Object-oriented software development and patterns CASE tools Summary
2
Object-Oriention Concepts
Inception in early 1980s and nearing maturity. Widespread acceptance in industry and academics. Unified Modelling Language (UML) already an ISO standard (ISO/IEC 19501).
3
Objects
Consists of data (attributes) and functions (methods) that operate on data. Hides organization of internal information (Data abstraction).
4
Model of an Object
m8 m7 mi are methods of the object
m1 m2
Data
m6 m5 Object
m3
m4
Class
Abstract classes
LibraryMember
issueBook( ); findPendingBooks( ); findOverdueBooks( ); returnBook( ); findMembershipDetails( );
LibraryMember
for manipulating the data of other objects. by sending a message (method call). calculate_salary, issuebook, member_details, etc.
8
Invoked
Examples:
Aggregation/Composition
Dependency
Inheritance
Allows to define a new class (derived class) by extending or modifying existing class (base class).
Represents generalization-specialization relationship. Allows redefinition of the existing methods (method overriding).
10
Inheritance
Lets a subclass inherit attributes and methods from more than one base class.
LibraryMember
Base Class
Faculty
Students
Staff
Derived Classes
UnderGrad
PostGrad
Research
11
Inheritance Example
Library Book
issuable reference
Issuable BookSet
Reference BookSet
12
Multiple Inheritance
cont
LibraryMember Base Class
LibraryMember Base Class
Faculty
Students
Staff
Students
UnderGrad
PostGrad
Research
UnderGrad
PostGrad
Research
13
Association Relationship
one object must know the address of the corresponding object in the association.
in general can be n-ary.
14
Usually binary:
But
Association Relationship
Give an example?
An arrowhead used along with name, indicates direction of association. Multiplicity indicates # of instances taking part in the association.
15
Association Relationship
Library Member
borrowed by
Book
16
3-ary Association
Person * * Skill
Competency level
17
A link:
An
For example:
An
instance of an association Exists between two or more objects Dynamically created and destroyed as the run of a system proceeds employee joins an organization, Leaves that organization and joins a new organization etc.
18
Aggregation Relationship
It can be transitive
19
Aggregation Relationship
Document
* Paragraph
* Line
20
Composition Relationship
Item
21
Aggregation
cont
22
Inheritance:
Different
Cont
features.
Necessary
Aggregation:
Containment
23
Composition:
Composite and components have the same life. Lifelines are different.
Aggregation:
24
Order
Item
Composition
Order
Item
Aggregation
25
Class Dependency
Dependent Class Independent Class
26
Abstraction
non-relevant aspects
Types of abstraction:
Data
abstraction
abstraction
27
Behaviour
Abstraction
Advantages of abstraction:
Reduces
cont
complexity of design
understandability
Enhances
Increases
productivity
proportional to complexity.
28
Encapsulation
Encapsulation
cont
m4
m3
m5
m2
Data
m6 m1
Methods
Concept of encapsulation
30
Polymorphism
Static binding
Dynamic binding
31
Class Circle{
private float x, y, radius; private int fillType; public create (); public create (float x, float y, float centre);
32
cont
Without any parameter, default Centre and radius as parameter Centre, radius and fillType as parameter
33
Dynamic Binding
34
Would
Dynamic Binding
An object can be assigned to an object of its ancestor class, but not vice versa.
A B A a; B b; a=b; (OK) b=a; (not OK)
35
Dynamic Binding
Cont
Dynamically
36
method is declared in the shape class and overridden in each derived class.
single call to the display method for each object would take care of displaying the appropriate element.
37
Circle
Rectangle
Line
Ellipse
Square Cube
38
An Example
cont
Traditional code
Shape s[1000]; For(i=0;i<1000;i++){ If (s[i] == Circle) then draw_circle(); else if (s[i]== Rectangle) then draw_rectangle(); }
Object-oriented code
Shape s[1000]; For(i=0;i<1000;i++) Shape.draw(); -
Ability to parameterize class definitions. Example: class stack of different types of elements: Integer stack Character stack Floating point stack Define generic class stack:
Genericity
40
Genericity
Set
insert(T) remove(T)
Refinement
EmployeeSet
41
Elegant design:
Loosely coupled, highly cohesive objects: Essential for solving large problems.
42
Used to document objectoriented analysis and design results. Independent of any specific design methodology.
44
UML Origin
software development houses were using different notations. Methodologies were tied to notations. Standardize the large number of object-oriented modelling notations
45
UML Lineology
[Rumbaugh 1991] methodology[Booch 1991] [Jacobson 1992] methodology[Odell 1992] and Mellor [Shlaer 1992]
46
Boochs OOSE
Odells Shlaer
UML
OOSE
Boochs Methodology
47
UML as A Standard
car manufacturing
48
Developments to UML
UML 1.0
UML 1.X
UML 2.0
only important aspects and ignores the rest. models result when different aspects are ignored. effective mechanism to handle complexity.
50
Different
An
Modeling a House
51
UML Diagrams
Views of a system:
Users
Structural Behavioral
Implementation Environmental
view
53
UML Diagrams
Structural View
- Class Diagram - Object Diagram
Behavioural View
Users View
-Use Case Diagram
Implementation View
- Component Diagram
Environmental View
- Deployment Diagram
NO
Use case diagram, class diagram and one of the interaction diagram for a simple system State chart diagram required to be developed when a class state changes
However, when states are only one or two, state chart model becomes trivial
Deployment diagram in case of large number of hardware components used to develop the system
55
model
Not
Represents
model
a functional or process
56
Use Cases
Different ways in which a system can be used by the users Corresponds to the high-level requirements Represents transaction between the user and the system Defines external behavior without revealing internal structure of system Set of related scenarios tied together by a common goal.
57
Use Cases
Normally, use cases are independent of each other Implicit dependencies may exist
Cont
Example: In Library Automation System, renew-book & reserve-book are independent use cases.
But in actual implementation of renew-book: a check is made to see if any book has been reserved using reserve-book.
58
issue-book
query-book
return-book create-member add-book, etc.
59
Play Move
Player
Tic-tac-toe game
61
User identification helps in implementing appropriate interfaces for different categories of users Another use in preparing appropriate documents (e.g. users manual).
62
use cases need to be factored into simpler use cases To represent common behavior across different use cases
63
64
<<include>> <<include>>
65
<<extends>>
66
External users
Subsystems
use case 3. 2
use case 3
Method
67
Receive grant
Make payments
68
Class Diagram
Describes static structure of a system Main constituents are classes and their relationships:
Generalization Aggregation Association Various
kinds of dependencies
69
Class Diagram
Object Diagram
LibraryMember Mritunjay B10028 C-108, Laksmikant Hall 1119 Mrituj@cse 25-02-04 25-03-06 NIL IssueBook( ); findPendingBooks( ); findOverdueBooks( ); returnBook( ); findMembershipDetails( ); LibraryMember Mritunjay B10028 C-108, Laksmikant Hall 1119 Mrituj@cse 25-02-04 25-03-06 NIL LibraryMember
Interaction Diagram
72
Interaction Diagram
Two kinds: Sequence and Collaboration diagrams. Two diagrams are equivalent
Portray
different perspectives
Sequence Diagram
Objects existence are shown as dashed lines (lifeline) Objects activeness, shown as a rectangle
on lifeline
74
object
control
val idate i f ( paymen t ok ) del iver i f ( not in stock ) back order get address
lifetime
m ail to a ddress
message
76
Example
Cont
: Custom er : Order : Payme nt : Prod uct : Suppl ier
val idate
77
:Book
:Library Member
find MemberBorrowing
apology confirm
confirm
update
updateMemberBorrowing
78
Collaboration Diagram
Shows both structural and behavioural aspects Objects are collaborator, shown as boxes Messages between objects shown as a solid
line
A message is shown as a labelled arrow placed near the link Messages are prefixed with sequence numbers to show relative sequencing
79
4: selectBooks
12: confirm
80
Activity Diagram
Represents processing activity, may not correspond to methods Activity is a state with an internal action and one/many outgoing transitions Somewhat related to flowcharts
81
Swim lanes can be used to group activities based on who is performing them
Example: academic department vs. hostel
82
Activity Diagram
Carried out during requirements analysis and specification stage. Can be used to develop interaction diagrams.
83
allot hostel
receive fees
allot room
84
Order Processing
Stock Manager
Receive Supply
Authorize Payment
[succeeded]
[need to reorder] Reorder Item [stock assigned to all line items and payment authorized] [all outstanding order items filled]
Dispatch Order
85
Model how the state of an object changes in its lifetime Based on finite state machine (FSM) formalism
86
State chart avoids the problem of state explosion of FSM. Hierarchical model of a system:
Represents
states
composite nested
87
Elements Initial
Final
State: A filled circle inside a larger circle Rectangle with rounded corners Arrow between states, also boolean logic condition (guard)
88
State:
Transitions:
Unprocessed Order
[accept] checked
Rejected Order
[some items not available] processed
Accepted Order
[some items available] processed / deliver
[all items available] newsupply
Pending Order
Fulfilled Order
89
Package Diagrams
A package is a grouping of several classes:
Java packages are a good example
Order Capture UI AWT Mailing List UI
Package diagrams show module dependencies. Useful for large projects with multiple binary files
Common {global}
Oracle Interface
Domain
Sybase Interface
Orders
Customers
90
Component Diagram
dependency
91
Component Diagram
92
Deployment Diagram
A piece of hardware
93
A Design Process
Developed
However, UML has been designed to be usable with any design methodology.
From
Design
OOAD
Iterative and Incremental
OOA
Specification
OOD/OOP
Domain Model
Program
95
OOD
Use case diagram Interaction diagram
Start
SRS document
Domain model
Class diagram
Code
Glossary
96
Domain Modelling
Represents Also
concepts or objects appearing in the problem domain. captures relationships among objects.
Three
Boundary objects
Entity objects
Controller objects
97
Class Stereotypes
Three different stereotypes on classes are used: <<boundary>>, <<control>>, <<entity>>.
Boundary
Cashier Interface
Control
Withdrawal
Entity
Account
98
Boundary Objects
Interact
with actors:
Include
Do
screens, menus, forms, dialogs etc. not perform processing but validates, formats etc.
99
Entity Objects
Hold information:
Normally are dumb servers Responsible for storing data, fetching data etc.
Controller Objects
Entity 1
Entity 2
Entity 3
Realization of use case through the collaboration of Boundary, controller and entity objects
102
Class-ResponsibilityCollaborator(CRC) Cards
Pioneered
Index
Class
Collaborating
Team
104
BookRegister
FindBook CreateBook Reserve Book Book Book
Responsibility
Collaborator
A pattern:
Still describes a recurring problem Provides a more specific solution, with fewer variations
Patterns
If you can master a few important patterns, you can easily spot them in application development and use the pattern solutions.
107
Idioms
In English:
A group of words that has meaning different from a simple juxtaposition of the meanings of the individual words. Raining cats and dogs for(i=0;i<1000;i++){
A C idiom:
108
Antipattern
Design Patterns
Which class should be responsible for doing certain things Assign responsibility to the class that has the information necessary to fulfil the required responsibility
111
Solution:
1:total
:SaleTransaction
2: subTotal
:SaleItem
3: price
:ItemSpecification
Collaboration Diagram
112
Which class should be responsible for creating a new instance of some class? Assign a class C1 the responsibility to create class C2 if
Solution:
Who should be responsible for handling the actor requests? Separate controller object for each use case.
Solution:
114
Context
Solution:
Model-View-Controller
How should the user interface (Boundary) objects interact with the other objects?
Solution 1: Pull from Above
Solution 2: Publish-Subscribe
The boundary objects register themselves with an event manager object. Other objects, notify the event manager object as and when an event of interest occurs. The event manager notifies those boundary objects that have registered with it by using a call back.
117
If neither player manages to get three consecutive marks along a straight line,
And all the squares on the board are filled up, Then the game is drawn.
Play Move
Player
Tic-tac-toe game
120
121
:playMove Controller
checkMoveValidity [invalidMove] announceInvalidMove checkWinner [game over] announceResult playMove
:board
checkWinner
[game over] announceResult displayBoardPositions [game not over] promptNextMove [game over] announceResult getBoardPositions
122
Controller
announceInvalidMove announceResult
123
Supermarket needs to develop software to encourage regular customers. Customer needs to supply his:
Residence address, telephone number, and the driving licence number. Assigned a unique customer number (CN) by the computer.
124
A customer can present his CN to the staff when he makes any purchase. The value of his purchase is credited against his CN.
At the end of each year:
The supermarket awards surprise gifts to ten customers who make highest purchase.
125
the last day of every year after the prize winners lists are generated.
126
Customer
Clerk
Manager
127
SalesHistory
1 *
CustomerRegister
1 *
SalesRecords
CustomerRecord
128
CustomerRegister
1 *
SalesRecords RegisterCustomerBoundary
CustomerRecord RegisterCustomerController
RegisterSalesBoundary
SelectWinnersBoundary
RegisterSalesController
SelectWinnersControllers
129
:SelectWinner Controller
:Sales History
:Sales Record
:Customer Register
:Customer Record
SelectWinners
SelectWinners *computeSales
*browse
announces
130
:RegisterCustomer Controller
:Customer Register
:Customer Record
register
displayCIN
131
:Sales Record
confirm
create
:Sales Record
confirm
134
Summary
mechanisms: Such as objects, class, methods, inheritance etc. concepts: Such as abstraction, encapsulation, polymorphism, composite objects etc.
135
Summary
Its origin, as a standard, as a model Use case representation, its factorisation such as generalization, includes and extends Different diagrams for UML representation
In class diagram we discussed some relationships association, aggregation, composition and inheritance
136
Summary
cont
Interaction diagrams (sequence and collaboration), Activity diagrams, State chart diagrams.