Week 2 - OOAD
Week 2 - OOAD
Model and design flexible software at the architectural level using various tools and techniques;
Take requirements for simple systems and develop software architectures and designs at a high level;
What is OO Analysis?
• Analysis:
• Investigation of problem and the requirements.
• OO Analysis:
• emphases finding and describing objects and related concepts in the problem domain.
• Tool
• Block diagram
• UML
• usecases to analyse requirements.
• Class diagrams to model the domain after use cases are developed
• Interaction diagrams to design the model.
Use Cases
The indispensable first step to getting the things you want out of life: decide what
you want. ---Ben Stein
Specifications
Example
Scenario
A customer arrives at a checkout with items to return. The cashier uses the POS system to
record each returned item ...
If the customer paid by credit, and the reimbursement transaction to their credit account is
rejected, inform the customer and pay them with cash…
If the system detects failure to communicate with the external accounting system, ...
Use Case
Definitions
• A collection of related success and failure scenarios that describe an actor using the
system under discussion to support a goal.
• They are requirements, primarily functional or behavioural requirements that indicate what
the system will do.
• A use case captures a contract between the stakeholders of a system about its behaviour –
Cockburn.
• A useful tool for formalizing your understanding of requirements.
• What is an actor?
• something with behaviour (or that acts as a result of an action), such as a person (e.g. cashier),
computer system or organisation.
Use Case
Actors
Types
• Primary: An actor that initiates the use case or an actor whose goals fulfilled through using
services of the system under discussion (e.g., Client).
• Supporting (Secondary): That facilitates the primary actor or provides a service to
achieve the primary goal (e.g., Cashier)
• Offstage (External): has an interest in the behaviour of the use case, but is not primary or
supporting (e.g., a government tax agency).
Note: the system under discussion is never an actor. Other systems can be.
Use Case
Types
• OMG has defined standards for what should be in Use Case and how they can by
described.
• Primarily Use cases can be described in two forms
• Use Case Descriptions/Scenarios
• Use Case Diagrams.
Use Case
Use Case Descriptions/Scenarios
Level of Details.
• High-level (Brief)
• Terse description of the activities without going into details of how activities are performed
• Casual
• Brief but including the alternative and extension scenarios
• Expanded (Fully Dressed)
• shows more detail than a high-level one, details the sequence of events in the process
• generally done in a conversational style
• show alternative courses
• shows the initiator of the use case
Use Case
Use Case Descriptions/Scenarios
Definitions
• Illustrates a set of use cases for a system:
• the actors
• the relationships between actors and use cases
• the relationships between use cases and other use cases
• Each use case diagram typically shows actors and use cases for a particular (subset of)
system functionality.
Use Case
Use Case Diagrams
Relationships
• In many situations we find that use cases are very similar or have similar passages and
relationships.
• We need mechanisms to handle these relationships.
• UML provides three mechanisms:
• Generalisation
• Include
• Extend
Use Case
Use Case Diagrams
Generalisation
• This means that a child use case inherits and/or implements the behaviour and meaning of
the parent use case
• The child may add to or override the behaviour of the parent
• The child may be substituted in any place the parent may appear in the system
• Generalization appears as:
Use Case
Use Case Diagrams
Include
• A use case incorporates the behaviour of another use case at a location specified in that
use case.
• An including use case never stands alone. It always includes the included use case
• The included use case, however, can
• The include relationship is used to avoid describing the same flow of events several times,
by putting the common behaviour in a use case of its own
Use Case
Use Case Diagrams
Include - Example
• Once you are placing an order or tracing an order a verification is needed. Though verification is a
separate independent use case for place order and trace order, it is mandatory otherwise the place
order and trace order will not be successfully completed.
Use Case
Use Case Diagrams
Extend
• “Extend” is used to separate optional behaviour from mandatory behaviour
• The base use case optionally incorporates the behaviour of another use case at a specified
location
• The extended use case may stand alone, but, under certain conditions, it may be extended by another
use case.
• It may be extended only at certain points known as “extension points”
Use Case
Use Case Diagram
Extend - Example
• While placing an order online I would like the order to be wrapped or not. It is optional and
the use case place order can still be successfully completed if we don’t ask for wrapping.
Use Case
Use Case Diagram System
Complete Example
Use Cases
Use Case
Strengths and Weaknesses
Strengths
• Use cases directly relate to actors. Hence, they directly relate to the users of the system
and specifies the suite of interactions with the system.
• Use cases help the business analyst to document requirements in a commonly accepted
format in the problem space of the project.
• Use cases capture the functional aspects of the system. More specifically, they capture the
business processes carried out in the system.
• Use cases facilitate tracing of requirements.
• Use cases can also provide a starting point for sequence diagrams
• Use cases are the basis for test case development.
Use Case
Strengths and Weaknesses
Weaknesses
• Use case documentation is not standardised. This leads to confusion and debates on what
makes up a good use case.
• Use cases are not object-oriented in nature.
• Use cases do not cover nonfunctional (operational) requirements
• Use cases do not provide a good basis for coding.
Activity
It’s all well in practice, but it will never work in theory. --- Anonymous Management
Maxim
Basics of OOP
Pre-Requisites
Classes
A class is a template for Objects
Class is an abstraction of all existing and new objects with similar
characteristic
Objects
Objects are instances of a class
Data stored inside the object fields is often references as state and all object methods define it’s
behaviours
Pillars of OOP?
Domain Modelling
Conceptual Classes
Definition
A domain model is a representation of real-world conceptual classes, not of software
components. It is not a set of diagrams describing software classes, or software objects with
responsibilities.– Larman
• So what is conceptual class?
• conceptual class is an idea, thing, or object
• We model identity, state, and behaviour
• It represents things in the real world, not classes in code
• How to capture them?
• UML Class Diagram
Domain Modelling
Class Diagram
Components
• Classes
• Rectangle containing the class name
• and optionally fields/states/attributes and
methods/behaviours/operations.
• Classes have relationships that are:
• Associations
• Dependency
• Aggregation
• It can be shared or composite
• Generalisation
Domain Modelling
Class Diagram
Associations
• Associations
• Association is a type of relationship in which one object uses or interacts with another.
• In UML diagrams the association relationship is shown by a simple arrow drawn from an object and pointing
to the object it uses.
• use an association to represent something like a field in a class
• Associations should be named
• Note: the name ‘has’ adds very little to understanding.
• Associations have multiplicities.
Domain Modelling
Class Diagram - Reading direction arrow
- It has no meanings except reading
Associations - Code the direction of association label.
- It is different from association
direction.
Associations - Multiplicities
• Multiplicities can be
• One to many
• Many to many
• Zero to many
• Exactly
• Its is not ERD diagram so don’t use m or n for many
multiplicities. However, in some conditional cases
we may use m and n.
Domain Modelling
Class Diagram
Dependency
• Dependency is a weaker variant of association that usually implies that there’s no permanent link between
objects.
• Dependency typically (but not always) implies that an object accepts another object as a method parameter,
instantiates, or uses another object.
• A dependency exists between two classes if changes to the definition of one class result in modifications in
another class.
Domain Modelling
Class Diagram
Dependency
Aggregation
• Aggregation appears between classes when one object merely contains a reference to another
• There is a sharing of classes happening i.e. The component can exist without the container and
can be linked to several containers at the same time.
• In UML it is shown by a diamond sign which can be directional.
Domain Modelling
Class Diagram
Composition
• Is a type of aggregation which shows a “whole-part” relationship between two objects, one of which is
composed of one or more instances of the other.
• The distinction between this relation and others is that the component can only exist as a part of the
container.
• composition relationship is shown by a line with a filled diamond at the container end.
• It can be directional.
Domain Modelling
Class Diagram
Generalisation (is-a)
Methods
• Make a list of candidate conceptual classes or attributes by identifying nouns in textual domain
descriptions
• Scenario: Process Sale (Basic Flow)
• Customer arrives at POS checkout with goods and/or services to purchase. Cashier starts a new sale.
Cashier enters item identifier. System records sale line item and presents item description, price, and
running total. Price calculated from a set of price rules.
• Cashier repeats steps 2-3 until indicates done. System presents total with taxes calculated. Cashier tells
Customer the total, and asks for payment.
• And so on…
• Guideline: Careful evaluation required: not mechanical.
Domain Modelling
Identifying Domain Classes
• Make a list of candidate conceptual classes in the domain, based on commonly occurring
categories.
• Sometimes they are physical objects or abstract concepts.
Candidate classes
Rejecting Classes
Examples
Domain Modelling
Identifying Domain Classes
Example 2
Purpose
You’re creating the diagram to ensure that you, your team, and your clients all share an
understanding of how the domain works.
Important classes.
• talk to the customer or user to see what’s important to them.
• Include only class names, at least initially. You can add data storage and responsibilities as they become
clear to you, if you find that you need to clarify them, but you only need to put them in if the diagram is
hard to understand without them.
Relationships between these classes.
• Start off with generalisation (i.e. inheritance) and associations.
• If you can’t decide between composite or shared aggregation, leave it as an association for the
time being.
Note: At the conceptual level, names and types of attributes are typically not yet known
DESIGN MODELLING
In theory, there is no difference between theory and practice. But, in practice, there
is. --Jan L. A. van de Snepscheut
Design Modelling
Introduction
Definition
• shows object interactions arranged in time sequence.
• It depicts the objects involved in the scenario and the sequence of messages exchanged
between the objects needed to carry out the functionality of the scenario.
Design Modelling
Sequence Diagrams
Lifelines
• Lifelines demonstrates an
object and it is shown as a
box.
Design Modelling
Sequence Diagrams
Messages
• Messages are written as
horizontal arrows.
Design Modelling
Sequence Diagrams
Showing Results
• If there is a return call that
will be shown by a broken
horizontal line.
Design Modelling
Sequence Diagrams
Object Destruction
• Objects can be destructed.
Design Modelling
Sequence Diagrams
Frames
• Three types of frames are
used
• Loops
(loop)[condition or items]
• If/then
(opt)[condition]
• If/then/else
(alt)[condition or else]
with dashed separator
Design Modelling
Sequence Diagrams
Frames – sd/ref
• Sd -> Define
• Ref -> refer
Design Modelling
Deriving a SSD from a Use Case.
Design Modelling
Communication Diagrams
Beware of bugs in the above code; I have only provide it correct, not tried it. –
Donald Knuth
Mapping Designs to Code
Sequence Diagrams.
Mapping Designs to Code Public class SalesLineItem{
private int quantity;
private ProductDescription description;
Class Diagrams
public SalesLineItem(ProductDescription desc, int qty){
…
Examples }
public Money getSubtotal(){…}
}
Design Modelling
Class Diagrams
Examples
Mapping Designs to Code
Sequence Diagrams
Examples
Design Modelling
Class Diagrams
Examples