Week 02-03
Week 02-03
2
Design
(Recap)
• The purpose of design is to produce a solution to a problem:
• The problem: requirements specification.
• The solution: your description of how the requirements are to
be met.
3
Design
(Cont...)
Design
Design Solution
A system that
provide complete
detail of airline
.reservation system
Reference [1] *
4
Software Design
5
Goals of Software Design
6
Goals of Software Design (Cont...)
Reference [3] *
12
Correctnes
s
• Software is correct, if it satisfies its requirements.
8
Approaches to Correctness
• Formal Approaches
– Involve applying logic to analyzing the way in which the variables
change
– Usually applied when the design enters the detailed stage
9
Informal Approach: Sufficient Design
A design sufficient
Minimum to implement the a Correct Design
Goal requirements Sometimes
called ....
11
Flexibility
• Flexible design implies a design that can easily accommodate
the changes
12
Aspects of Flexibility
Reference [4] *
13
Flexibility: Designs for Adding More of
the Same Kind of Functionality
• Registering members at online shopping website
Design 1
WebSite n . .0
Member
)(Register
Customer Visitor
14
Flexibility: Design for Adding Different
Functionality
• Case 1: Handled by adding the new method to an existing set
of methods of a class
WebSite
n . .0
Register() Member
)(maintainRecord
WebSite n . .0 Member
)(Register Log-
)(in
Customer Visitor
)( Log-in )(Log-in
15
Flexibility: Changing Functionality
WebSite n . .0 Member
)(Register Log-
)(in
Customer Visitor
Log-in() )(Log-in
)(AddCart
Product
)(ItemList
16
Reusability
• Designing a software system such that components of a
developed system can be used again in developing new
applications
17
Modularity
• Use modularity
Shape
D Shape-2 D Shape-3
Square
18
Reusability: Promoting Source Code
Reuse (Cont...)
• Use Classes
Reference [5] *
19
Efficiency
• Applications must execute functionality within
required required time constraints.
20
Reliability
• Reliability– mean time to failure (system crash, error)
21
Usability
.Users must find software easy to easy •
,Good documentation •
22
Today’s Agenda
2
SOLID
• Five principles of OOD Oriented
fundamental (Object
Design)...
• What is OOD ??
– In software development, OOD addresses the bigger picture. You need
to design your software in a way that your classes and code are
modularized, re-usable, and flexible.
– There are some design principles that you can apply to design your
classes and objects.
2
Why
?OOD
2
Principles of OOD
1. Single Responsibility Principle
2. Opened Closed Principle
3. Liskov Substitution Principle
4. Interface Segregation Principle
5. Dependency Inversion Principle
2
Single Responsibility Principle
Principle:
A class should have
one and only one
responsibility.
Reference [2] *
10
Single Responsibility Principle
Principle:
A class should have
one and only one
responsibility.
Reference [3] *
11
Example Rectangle class performs
two things
1. Rectangle: class
Thisshould
the area() method. define
inherit
the
Rectangle
class
Principle:
Software entities (classes,
modules, ,functions etc.)
should be open
extension, for closed
modification.
but
for
Reference [4] *
30
Open-Closed Principle (Cont...)
• Example: we should strive to write code that doesn’t have
to be changed every time the requirements change
31
Liskov's Substitution Principle
Principle:
Subclasses should be
substitutable for their base
classes.
32
Liskov's Substitution Principle
(Cont...)
Design
Bird Violate
)(Fly s LSP
33
The Interface Segregation Principle
Principle:
Subclasses should not
be forced to depend
upon interfaces that
they do not use
34
The Interface Segregation Principle
(Cont...)
35
Fat interface
Example of an interface violating the
Interface Segregation principle
Bird
)(Eat Bird interface has many bird
behaviours along
Walk() defined the Fly() with
behaviour.
Chirp() Now, if a Bird class (say, Ostrich
)( Fly class) implements this interface, it
has to implement the Fly() behaviour
unnecessarily (Ostrich doesn't fly).
Eagle Ostrich
36
Solution: Fat Interface
• The "Fat Interface" should be broken down into two
different interfaces.
Bird
)(Eat
)(Walk Correct version of the interface in the Interface
Segregation principle example
)(Chirp
FlyingBird
)(Fly
37
Example
Bird
)(Eat
Walk()
)(Chirp
FlyingBird Ostrich
)(Fly
Eagle
38
The Interface Segregation Principle
(Cont...)
• This principle ensures that Interfaces are developed so that
each of them have their own responsibility and thus they are
specific, easily understandable, and re-usable.
39
The Dependency Inversion Principle
:Principle
"High level modules
should not upon
low level modules. Rather,
depend
both should depend upon
abstractions."
40
The Dependency Inversion Principle
41
The Dependency Inversion Principle
42
References
1. http://www.stefanolocati.it/blog/?p=1173
2. http://wilmurphy.com/what-can-setting-goals-do-
for-you/
3. http://www.codesimplicity.com/post/the-goals-of
- software-design/
4. http://en.wikipedia.org/wiki/Overdraft
5. http://shivasoft.in/blog/java/difference-between-
interfaceinheritance-abstract-class/
6. http://www.softwaremetrics.com/Articles/estima
ting
.htm 43