Module 5
Module 5
Module 5
1. Introduction
2. Object Oriented Fundamentals
3. O.O Analysis: Dynamic Model
4. O.O Analysis: Static Model
5. Object Oriented Design
Object Oriented Design
1. Object Oriented Design
2. OO Design - Static Model
3. OO Design - Dynamic Model
4. State Transition Diagram
5. Design Principles
6. Design Patterns
1. OBJECT ORIENTED DESIGN
Introduction
• Design is the bridge between the analysis and implementation of the
software system
• During this phase, we must:
• Assign responsibilities to the system objects
• Normalize our diagrams
• Add additional information to them before proceeding with
implementation
• Created separately
Business
• Focus on quality: looking to ensure reliability, performance,
Logic layer
ef ciency and reusability at architectural level
Presentation • Responsible of the user interface. It obtains data from the business logic layer and it displays it.
layer
Business • Responsible of business logic, system features. It get data and sends it, after treating it, to the
Logic layer presentation layer.
Data Access • Stores and retrieve persistent data, sends it to the business logic layer
layer
Software Architecture
fi
Implementation model
• The class diagram is modi ed to and we:
• Remove associations involving more than two classes
• Remove associative classes
• We decide how to process the derived information
• The integrity of the conceptual data model and the operation contracts
needs to be, both of them, normalized.
fi
Implementation model
Implementation model
Derived information
• After leading with associations involving more than two classes we need to see how we deal with derived
information.
• Derived information refers to the data or attributes that can be calculated or derived based on other attributes or
operations of the class.
• Derived information can be computed dynamically or statically by the class
• Example:
• "Rectangle" class has attributes for its "width" and “height", meaning that "area" attribute is made of
derived information
• Another example of derived information could be a "Person" class that has attributes for "date of birth"
and "current date". The "age" attribute of the person can be calculated as a derived information based on
the difference between the "date of birth" and "current date”
• Derived information is usually represented in a class diagram as a derived attribute or operation, with a slash ("/")
preceding its name to indicate that it is not a physical attribute but is instead calculated based on other attributes or
operations.
Derived information
• Dealing with this derived information while normalising, means:
• We delete the “/“ from the class diagram.
• We have two options to deal with this “/“ removed:
• We review the operation contracts responsible for calculating and
recording this values
• We add methods that calculate the value inside the classes
Derived information
Derived information
In this case, operation contract responsible of creating and invoice (issuedBy) and the one closing the rental (price) will have to be updated.
3. OO DESIGN - DYNAMIC
MODEL
Operation Contracts Normalisation
• Once we have detected all the things that needs to be normalized in the
class diagram we have:
• All associations are binary. Classes and multiplicity have been added/
modi ed but the meaning is the same.
• Updated or removed integrity restrictions
• Decided how to handle derived information
• Now we need to update the contracts!
fi
Operation Contracts Normalization
• Basically, we add more detail in terms of related objects and when the
operations will be valid or not, taking into account the new relations we
created in the class diagram.
Operation Contracts Normalization
Not normalized
Normalized
Operation Contracts Normalisation
• Basically, when the operation contracts have been normalised:
• We assign responsibilities to classes (when normalising the class
diagram, we create new classes and operations)
• We establish new collaborations between classes (we establish
navigability after normalising and we can design a system sequence
diagram)
Type of classes
• From all this classes that may appear after normalising we Presentation
can nd different ones: layer
• Boundary classes: required by the user interface
design (screen containing graphic objects, menus…)
• In the presentation layer
• Control classes: controlling different operations Business
Logic layer
• Bridge between presentation and business logic
layer
• Usually there’s a control class for each use case
• Entity classes: model real world entities, and the Data Access
objects created in this classes needs to be persistent layer
(they are the classes that appear on the normalized
conceptual diagram)
fi
Type of classes
• In order to represent all this classes and Presentation
layer
how they interact, we create sequence
diagrams:
• They explicitly identify the classes
Business
involved in each system operation, the
Logic layer
messages send between objects and
the order in which they are send.
Data Access
layer
UML - Sequence Diagram
• Two read directions:
• Horizontally: arrows indicate the direction of the message
• Vertically: chronological order of messages
UML - Sequence Diagram
• Constructor case:
• The object name is aligned with
the message that created it
• A constructor call always returns
the object instance
• If needed, we can explicitly
destroy an object
UML - Sequence Diagram
• Internal operation case:
• We can call inner object
methods
• Execution speci cation for this
new operation is overlaid to the
previous one
fi
UML - Sequence Diagram
• Opt / alt and loop cases:
• Opt: option. An if condition
without else.
• Alt: one or more alternate
conditions, if the rst is not true,
it jumps to the following one (if
else)
• Loop: block of messages that
gets passed as long as the
condition is true
fi
UML - Sequence Diagram
UML - Sequence Diagram
Class Design
• Attributes are private by default.
• Operations are public by default.
• Each class has a constructor with parameters for each one of the class
attributes.
• Each class have getter and setters.
• If the object have states, there must be an operation that can edit this state
(makeAvailable, pendingPayment, paymentDone…)
Class and methods syntax
• Visibility: public (+), private (-), protected (#)
• Multiplicity: univalued, multivalued, with null value
• [Visibility] name [Multiplicity] : type [=initialValue] [{constraints}]
• - country: String = “Principat d’Andorra”
• + addCountry(numPass:Integer, countryName:String): Boolean
• + medianAge(): Real
Materialising the associations
• We add, at the end of the association in the class diagram, the role in the
sense of navigation
fi
State Transition Diagram
• State: period of time during the life of an entity in which a set of
conditions are satis ed
• Transition: state change triggered by an event
• It’s a summary of the dynamics of the system
fi
State Types
• Initial state: system init, constructor
call…
• Final state: session ends, object
destroyed…
• Intermediate state: states of the
system, objects…
• Simple state: no internal transition
in this state
State Types
• Transition from initial state
indicates in which state the system
is initialised
• Many states can have transition to
the nal state
• The name of each state (inside
rectangles) must be unique
fi
State Types
• We can add state characteristics, explaining everything that needs to happen
to stay in the current state.
Event Types
• The expected events are all the events that may trigger a state transition
Event Types
• Events can be:
• Signal event: asynchronous message or signal
• Call event: calling an operation (for example the ones de ned in the class
diagram)
• Condition event: when (condition) —> condition is a Boolean expression that is
constantly evaluated until it’s true
• Time event:
• Relative date: after (Time)
• Absolute date: when (date=Date)
fi
Transition / Action
• The acton is the reaction of the system to an event, and it can be:
• Assign a value
• Calling an operation
• Sending a signal
• Creation or destruction of objects
• When an event arise, if the condition is true, the action is performed:
When do we use it
• During analysis:
• Dynamic behaviour seen from outside
• Describe the use cases and alternative scenarios
• Events are actions performed by actors
• During design:
• Dynamic behaviour of a single object
• Events are method calls
Example
5. DESIGN PRINCIPLES
Design principles
• Set of guidelines that help to improve the overall design
• Techniques that have been used with success in many object-oriented
designs
• By using them we avoid many common OO design mistakes resulting in
rigid, fragile and not reusable software
• The pillars for OOP are abstraction, encapsulation, inheritance and
polymorphism, as we’ve seen, but they are not enough to build high
quality software
• On top of this concepts, we apply design principles
GRASP principles
• First presented by Craig Larman’s
book: Applying UML and Patterns
• GRASP stands for:
• General Responsibility
Assignment Software Pattern
• Set of 9 design principles that help us
assigning responsibilities to classes
• We usually assign this responsibilities
during the creation of diagrams
GRASP principles
• Responsibility: obligation to perform a task or knowing an information.
• We can divide responsibilities in two types:
• Knowing responsibilities:
• Get private and public object data
• Get derived information
• Get object references
• Doing responsibilities:
• Do something: create an object, process data…
• Initiate and coordinate actions
GRASP principles
• GRAPS patterns:
• Information Expert
• Creator
• Low coupling
• High cohesion
• Controller
• Indirection
• Polymorphism
• Pure Fabrication
• Protected Variations
Information Expert
Problem: What is a basic principle by which to assign
responsibilities to objects?
Solution: Assign a responsibility to the class that has the
information needed to fulfil it