SlideShare a Scribd company logo
1 of 70
Download to read offline
1
‫ر‬َ‫ـد‬ْ‫ق‬‫ِـ‬‫ن‬،،،‫لما‬‫اننا‬ ‫نصدق‬ْْ‫ق‬ِ‫ن‬‫ر‬َ‫د‬
Faculty of Engineering - Helwan University
2
 Design bridges that gap between knowing what is needed
(software requirements specification) to entering the code
that makes it work (the construction phase).
 Design is both a verb and a noun.
3
 During the design phase, software engineers apply their
knowledge of the problem domain and implementation
technologies in order to translate system specifications
into plans for the technical implementation of the
software.
 The resulting design expresses the overall structure and
organization of the planned implementation. It captures
the essence of the solution independent of any
implementation language.
4
There is a famous cartoon showing
two professors at a chalkboard
examining a proof that includes the
step “then a miracle occurs”.
At times it seems like this is the
most that can be hoped for during
software design.
5
 There is a process for design but not an algorithm.
 Software design is a heuristic rather than deterministic
process.
 No reliable process for conjuring up a design
6
 Poorly designed programs are difficult to understand and
modify.
 The larger the program, the more pronounced are the
consequences of poor design.
Cost of adding the ith feature to a well-designed and poorly designed program
7
 To better understand how good design can minimize
technical complexity, it’s helpful to distinguish between
two major types of complexity in software:
 Essential complexities – complexities that are inherent in
the problem.
 Accidental/incidental complexities – complexities that are
artifacts of the solution.
 The total amount of complexity in a software solution is:
ESSENTIAL COMPLEXITIES + ACCIDENTAL COMPLEXITIES
8
 Design is the primary tool for managing essential and
accidental complexities in software.
 Good design doesn't reduce the total amount of essential
complexity in a solution but it will reduce the amount of
complexity that a programmer has to deal with at any
one time.
 A good design will manage essential complexities
inherent in the problem without adding to accidental
complexities consequential to the solution.
9
 MODULARITY – subdivide the solution into smaller
easier to manage components. (divide and conquer)
 INFORMATION HIDING – hide details and complexity
behind simple interfaces
10
 ABSTRACTION – use abstractions to suppress details in
places where they are unnecessary.
 HIERARCHICAL ORGANIZATION – larger components
may be composed of smaller components. Examples: a
complex UI control such as tree control is a hierarchical
organization of more primitive UI controls. A book
outline represents the hierarchical organization of ideas.
11
 Design is difficult because design is an abstraction of the
solution which has yet to be created
12
 The term wicked problem was first used to describe
problems in social planning but engineers have
recognized it aptly describes some of the problems they
face as well.
 A wicked problem is one that can only be clearly defined
by solving it.
 Need two solutions. The first to define the problem, and
the second to solve it in the most efficient way.
 Fred Brooks could have been talking about wicked
problems when he advised: “Plan to throw one away;
you will anyhow.”
13
 Any product that is an aggregate of more primitive
elements, can benefit from the activity of design.
14Standard Levels of Design
15
 Non-deterministic – A deterministic process is one that
produces the same output given the same inputs. Design
is non-deterministic. No two designers or design
processes are likely to produce the same output.
 Heuristic – because design is non-deterministic design
techniques tend to rely on heuristics and rules-of-thumb
rather than repeatable processes.
 Emergent – the final design evolves from experience and
feedback. Design is an iterative and incremental process
where a complex system arises out of relatively simple
interactions.
16
 Good design reduces software complexity which makes the
software easier to understand and modify. This facilitates
rapid development during a project and provides the
foundation for future maintenance and continued system
evolution.
 It enables reuse. Good design makes it easier to reuse
code.
 It improves software quality. Good design exposes defects
and makes it easier to test the software.
 Complexity is the root cause of other problems such as
security. A program that is difficult to understand is more
likely to be vulnerable to exploits than one that is simpler.
17
1. Understand the problem (software requirements).
2. Construct a “black-box” model of solution (system specification).
System specifications are typically represented with use cases
(especially when doing OOD).
3. Look for existing solutions (e.g. architecture and design patterns)
that cover some or all of the software design problems identified.
4. Design not complete? Consider using one or more design techniques
to discover missing design elements
 Noun-verb analysis, CRC Cards, step-wise refinement, etc.
 Take final analysis model and pronounce a first-draft design
(solution) model
5. Consider building prototypes
6. Document and review design
7. Iterate over solution (Refactor) (Evolve the design until it meets
functional requirements and maximizes non-functional
requirements)
18
 User requirements and system specification (including
any constraints on design and implementation options)
 Domain knowledge (For example, if it’s a healthcare
application the designer will need some knowledge of
healthcare terms and concepts.)
 Implementation knowledge (capabilities and limitations
of eventual execution environment)
19
 Patterns play an important role in the design methods of
today
20
 Methods and patterns are the principle techniques for
dealing with the challenges of design
 They are useful for:
 Creating a design
 Documenting and communicating a design
 Transferring design knowledge and experience between
practitioners
21
 A design pattern is a reusable solution to a commonly
occurring design problem
 Design patterns are adapted for the unique
characteristics of the particular problem
 Just as there are levels of design, there are levels of
design patterns:
 Architecture Styles/Patterns
 Design Patterns
 Programming Idioms
22
23
 Robert Martin
 "AGILE SOFTWARE DEVELOPMENT: PRINCIPLES,
PATTERNS, AND PRACTICES“
 “CLEAN CODE”
24
 Design is generally
“THE DECISIONS WE TAKE TO BUILD SOMETHING”
 Design + implementation = Product
 If we apply this to software:
DESIGN
+
PROGRAMMING / CODING
=
SOFTWARE PRODUCT
25
CHANGE
is
The only constant in software
26
if
CHANGE
is
The only constant in software
Then
MODIFIABILITY
Is a vital design consideration
27
 Increased difficulty to adapt and maintain
 Causes
 Communication/Documentation breakdown
• Maintainers not fully familiar with the original design
principles -> change works, but…
 Design is not resilient in the face of change
28
 Characteristics of a bad design:
 RIGIDITY - It is hard to change because every change affects
too many other parts of the system.
 FRAGILITY - When you make a change, unexpected parts of
the system break.
 IMMOBILITY - It is hard to reuse in another application
because it cannot be disentangled from the current
application.
 VISCOSITY: The law of least resistance when faced with a
choice
• Design viscosity: Hacks are easier/faster than preserving the
design
• Environment viscosity: Slow cycle time -> fastest choice
29
 SOLID
 Single Responsibility Principle
 Open Closed Principle
 Liskov Substitution Principle
 Interface Segregation Principle
 Dependency Inverison Principle
 Code becomes more Testably (remember TDD is not only
about testing, more important its about Design)
30
 "There should never be more than one reason for a class
to change." — Robert Martin, SRP paper linked from The
Principles of OOD
 My translation: A class should concentrate on doing one
thing and one thing only
31
 Two resposibilities
 Connection Management + Data Communication
interface Modem {
public void dial(String pno);
public void hangup();
public void send(char c);
public char recv();
}
32
 Separate into two interfaces
interface DataChannel {
public void send(char c);
public char recv();
}
interface Connection {
public void dial(String phn);
public char hangup();
}
33
 "Software entities (classes, modules, functions, etc.)
should be open for extension, but closed for
modification." — Robert Martin paraphrasing Bertrand
Meyer, OCP paper linked from The Principles of OOD
 My translation: Change a class' behavior using
inheritance and composition
34
// Open-Close Principle - Bad example
class GraphicEditor {
public void drawShape(Shape s) {
if (s.m_type==1)
drawRectangle(s);
else if (s.m_type==2)
drawCircle(s);
}
public void drawCircle(Circle r) {....}
public void drawRectangle(Rectangle r) {....}
}
class Shape {
int m_type;
}
class Rectangle extends Shape {
Rectangle() {
super.m_type=1;
}
}
class Circle extends Shape {
Circle() {
super.m_type=2;
}
}
35
 Impossible to add a new Shape without modifying
GraphEditor
 Important to understand GraphEditor to add a new
Shape
 Tight coupling between GraphEditor and Shape
 Difficult to test a specific Shape without involving
GraphEditor
 If-Else-/Case should be avoided
36
// Open-Close Principle - Good example
class GraphicEditor {
public void drawShape(Shape s) {
s.draw();
}
}
class Shape { //super class
abstract void draw();
}
class Rectangle extends Shape {
public void draw() {
// draw the rectangle
}
}
37
 "Functions that use pointers or references to base
classes must be able to use objects of derived classes
without knowing it." — Robert Martin, LSP paper linked
from The Principles of OOD.
 My translation: Subclasses should behave nicely when
used in place of their base class
38
// Violation of Liskov's Substitution Principle
class Rectangle
{
int m_width;
int m_height;
public void setWidth(int width){
m_width = width;
}
public void setHeight(int ht){
m_height = ht;
}
public int getWidth(){
return m_width;
}
public int getHeight(){
return m_height;
}
public int getArea(){
return m_width * m_height;
}
}
class Square extends Rectangle
{
public void setWidth(int width){
m_width = width;
m_height = width;
}
public void setHeight(int height){
m_width = height;
m_height = height;
}
}
39
class LspTest
{
private static Rectangle getNewRectangle()
{
// it can be an object returned by some factory ...
return new Square();
}
public static void main (String args[])
{
Rectangle r = LspTest.getNewRectangle();
r.setWidth(5);
r.setHeight(10);
// user knows that r it's a rectangle. It assumes that he's able to set the
width and height as for the base class
System.out.println(r.getArea());
// now he's surprised to see that the area is 100 instead of 50.
}
}
40
 "Clients should not be forced to depend upon interfaces
that they do not use." — Robert Martin, ISP paper linked
from The Principles of OOD
 My translation: Keep interfaces small
41
 Don’t force classes so implement methods they can’t
(Swing/Java)
 Don’t pollute interfaces with a lot of methods
 Avoid ’fat’ interfaces
42
//bad example (polluted interface)
interface Worker {
void work();
void eat();
}
ManWorker implements Worker {
void work() {…};
void eat() {30 min break;};
}
RobotWorker implements Worker {
void work() {…};
void eat() {//Not Appliciable
for a RobotWorker};
}
43
 Solution
- split into two interfaces
interface Workable {
public void work();
}
interface Feedable{
public void eat();
}
44
 "A. High level modules should not depend upon low
level modules. Both should depend upon abstractions.
B. Abstractions should not depend upon details. Details
should depend upon abstractions." — Robert Martin, DIP
paper linked from The Principles of OOD
 My translation: Use lots of interfaces and abstractions
45
//DIP - bad example
public class EmployeeService {
private EmployeeFinder emFinder //concrete class, not abstract. Can access a SQL DB for instance
public Employee findEmployee(…) {
emFinder.findEmployee(…)
}
}
46
 Now its possible to change the finder to be a
XmlEmployeeFinder, DBEmployeeFinder,
FlatFileEmployeeFinder, MockEmployeeFinder….
//DIP - fixed
public class EmployeeService {
private IEmployeeFinder emFinder //depends on an abstraction, no an implementation
public Employee findEmployee(…) {
emFinder.findEmployee(…)
}
}
47
 http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
 http://www.oodesign.com
 http://www.slideshare.net/enbohm
48
49
 In software engineering, a design pattern is a general
repeatable solution to a commonly occurring problem in
software design.
 A design pattern isn't a finished design that can be
transformed directly into code. It is a description or
template for how to solve a problem that can be used in
many different situations.
50
 A design pattern
 Design Patterns are time-tested common solutions to
recurring design problems.
 Are the answer to a question that commonly arises “How
can I … ?”
 Abstracts a recurring design structure
 Comprises class and/or object
• Dependencies
• Structures
• Interactions
• Conventions
 Names & specifies the design structure explicitly
 Distils design experience
51
52
 Can reuse solutions
 Gives us a head start (mostly design, but implementation
too)
 Avoids unanticipated results as we are using time-tested
solutions
 No need to reinvent the wheel
 Establish common terminology
 Design patterns provide a common point of reference
53
 Design patterns gained popularity in computer
science after a certain book was published in
1994 by four authors, commonly know as Gang
of Four or GOF
 Gang of Four (GoF) Gamma, Helm, Johnson,
Vlissides, - founders of movement.
 Gamma et al, Design Patterns: Elements of
Reusable Object-Oriented Software,
Addison Wesley, 1995.
 They offer advice and help for developing
quality software
 An object-oriented design pattern
systematically names, explains and evaluates
an important and recurring design in object-
oriented systems.
54
 A design pattern has 4 basic parts:
1. Pattern Name
2. Problem
3. Solution
4. Consequences and trade-offs of application
 Language- and implementation-independent
 A “micro-architecture”
 Adjunct to existing methodologies (Unified, OMT, etc.)
 No mechanical application
 The solution needs to be translated into concrete terms in the
application context by the developer
55
 Codify good design
 Distil and disseminate experience
 Aid to novices and experts alike
 Abstract how to think about design
 Give design structures explicit names
 Common vocabulary
 Reduced complexity
 Greater expressiveness
 Capture and preserve design information
 Articulate design decisions succinctly
 Improve documentation
 Facilitate restructuring/refactoring
 Patterns are interrelated
 Additional flexibility
56
Patterns
Creational
BehavioralStructural
57
 Ensure a class only has one instance, and provide a
global point of access to it.
Singleton
58
 Motivation
 How to cleanly provide access to a global variable?
 Structure
 Output
59
 There must be exactly one instance of a class, and it
must be accessible to clients from a well-known access
point.
 When the sole instance should be extensible by
subclassing, and clients should be able to use an
extended instance without modifying their code.
60
 Controlled access to sole instance.
 Reduced name space.
 Permits refinement of operations and representation
 Permits a variable number of instances.
61
Hayes
Modem
USR Modem
Zoom
Modem
Modem
< ? >
File Sync
Dedicated Modem
Send ()
Receive()
Dial () {}
Hangup () {}
Send ()
Receive()
Dial ()
Hangup ()
62
Hayes
Modem
USR Modem
Zoom
Modem
Modem
File Sync
Send ()
Receive()
Dial ()
Hangup ()
Dedicated Modem
Send ()
Receive()
Dedicated Modem
Adapter
Send ()
Receive()
Dial () {}
Hangup () {}
ADAPTER
(wrapper)
Convert the interface of a class into
another interface clients expect. Adapter
lets classes work together that couldn't
otherwise because of incompatible
interfaces.
64
 Motivation:
 Reuse of existing codebase in a situation that it did
not anticipate.
 structure:
65
 Applicability:
 You want to use an existing class, and its interface does
not match the one you need
 Consequences:
 The amount of adapting is needed
 Conceptual distance between adapter and adaptee can
cause undesirable side effects
Observer
(Publish-Subscribe)
Define a one-to-many dependency between
objects so that when one object changes
state, all its dependents are notified and
updated automatically.
68
 Motivation:
 Maintain consistency between collaborating objects
while maintaining loose coupling
 Structure:
69
 Applicability:
 When an abstraction has two aspects, one dependent on
the other.
 When a change to one object requires changing others,
and you don't know how many objects need to be changed.
 When an object should be able to notify other objects
without making assumptions about who these objects are.
 Consequences:
 Abstract coupling between Subject and Observer
 Support for broadcast communication
 Unexpected updates
 Dangling References
 Memory Issues
70

More Related Content

What's hot

Software Development Methodologies
Software Development MethodologiesSoftware Development Methodologies
Software Development MethodologiesNicholas Davis
 
User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15koolkampus
 
A presentation on software crisis
A presentation on software crisisA presentation on software crisis
A presentation on software crisischandan sharma
 
Software Engineering (Project Scheduling)
Software Engineering (Project Scheduling)Software Engineering (Project Scheduling)
Software Engineering (Project Scheduling)ShudipPal
 
Software engineering a practitioners approach 8th edition pressman solutions ...
Software engineering a practitioners approach 8th edition pressman solutions ...Software engineering a practitioners approach 8th edition pressman solutions ...
Software engineering a practitioners approach 8th edition pressman solutions ...Drusilla918
 
Introduction to Software Project Management
Introduction to Software Project ManagementIntroduction to Software Project Management
Introduction to Software Project ManagementReetesh Gupta
 
Risk management(software engineering)
Risk management(software engineering)Risk management(software engineering)
Risk management(software engineering)Priya Tomar
 
Software requirement engineering
Software requirement engineeringSoftware requirement engineering
Software requirement engineeringSyed Zaid Irshad
 
Software Metrics - Software Engineering
Software Metrics - Software EngineeringSoftware Metrics - Software Engineering
Software Metrics - Software EngineeringDrishti Bhalla
 
Software Engineering - chp3- design
Software Engineering - chp3- designSoftware Engineering - chp3- design
Software Engineering - chp3- designLilia Sfaxi
 
Chapter 13 software testing strategies
Chapter 13 software testing strategiesChapter 13 software testing strategies
Chapter 13 software testing strategiesSHREEHARI WADAWADAGI
 
Software Process Models
Software Process ModelsSoftware Process Models
Software Process ModelsHassan A-j
 

What's hot (20)

Software Development Methodologies
Software Development MethodologiesSoftware Development Methodologies
Software Development Methodologies
 
User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15
 
A presentation on software crisis
A presentation on software crisisA presentation on software crisis
A presentation on software crisis
 
Software Engineering (Project Scheduling)
Software Engineering (Project Scheduling)Software Engineering (Project Scheduling)
Software Engineering (Project Scheduling)
 
Software design
Software designSoftware design
Software design
 
Software design
Software designSoftware design
Software design
 
Software process
Software processSoftware process
Software process
 
Software engineering a practitioners approach 8th edition pressman solutions ...
Software engineering a practitioners approach 8th edition pressman solutions ...Software engineering a practitioners approach 8th edition pressman solutions ...
Software engineering a practitioners approach 8th edition pressman solutions ...
 
Introduction to Software Project Management
Introduction to Software Project ManagementIntroduction to Software Project Management
Introduction to Software Project Management
 
Generic process model
Generic process modelGeneric process model
Generic process model
 
Slides chapter 2
Slides chapter 2Slides chapter 2
Slides chapter 2
 
Risk management(software engineering)
Risk management(software engineering)Risk management(software engineering)
Risk management(software engineering)
 
Rad model
Rad modelRad model
Rad model
 
Software requirement engineering
Software requirement engineeringSoftware requirement engineering
Software requirement engineering
 
Software Metrics - Software Engineering
Software Metrics - Software EngineeringSoftware Metrics - Software Engineering
Software Metrics - Software Engineering
 
UML
UMLUML
UML
 
Software Quality Metrics
Software Quality MetricsSoftware Quality Metrics
Software Quality Metrics
 
Software Engineering - chp3- design
Software Engineering - chp3- designSoftware Engineering - chp3- design
Software Engineering - chp3- design
 
Chapter 13 software testing strategies
Chapter 13 software testing strategiesChapter 13 software testing strategies
Chapter 13 software testing strategies
 
Software Process Models
Software Process ModelsSoftware Process Models
Software Process Models
 

Similar to SE2018_Lec 18_ Design Principles and Design Patterns

SE2_Lec 19_Design Principles and Design Patterns
SE2_Lec 19_Design Principles and Design PatternsSE2_Lec 19_Design Principles and Design Patterns
SE2_Lec 19_Design Principles and Design PatternsAmr E. Mohamed
 
04 designing architectures
04 designing architectures04 designing architectures
04 designing architecturesMajong DevJfu
 
Design concepts and principle,
Design concepts and principle, Design concepts and principle,
Design concepts and principle, awikhan12
 
Function Oriented and Object Oriented Design,Modularization techniques
Function Oriented and Object Oriented Design,Modularization techniquesFunction Oriented and Object Oriented Design,Modularization techniques
Function Oriented and Object Oriented Design,Modularization techniquesnimmik4u
 
UNIT3 PART2.pptx dhfdifhdsfvgudf dhfbdhbffdvf
UNIT3 PART2.pptx dhfdifhdsfvgudf dhfbdhbffdvfUNIT3 PART2.pptx dhfdifhdsfvgudf dhfbdhbffdvf
UNIT3 PART2.pptx dhfdifhdsfvgudf dhfbdhbffdvfputtipavan23022023
 
Devnology back toschool software reengineering
Devnology back toschool software reengineeringDevnology back toschool software reengineering
Devnology back toschool software reengineeringDevnology
 
Excavating the knowledge of our ancestors
Excavating the knowledge of our ancestorsExcavating the knowledge of our ancestors
Excavating the knowledge of our ancestorsUwe Friedrichsen
 
Design concept -Software Engineering
Design concept -Software EngineeringDesign concept -Software Engineering
Design concept -Software EngineeringVarsha Ajith
 
Se ii unit2-software_design_principles
Se ii unit2-software_design_principlesSe ii unit2-software_design_principles
Se ii unit2-software_design_principlesAhmad sohail Kakar
 
Code Craftsmanship Checklist
Code Craftsmanship ChecklistCode Craftsmanship Checklist
Code Craftsmanship ChecklistRyan Polk
 
OOSE Unit 4 PPT.ppt
OOSE Unit 4 PPT.pptOOSE Unit 4 PPT.ppt
OOSE Unit 4 PPT.pptitadmin33
 
Oose unit 4 ppt
Oose unit 4 pptOose unit 4 ppt
Oose unit 4 pptDr VISU P
 
Software engg. pressman_ch-9
Software engg. pressman_ch-9Software engg. pressman_ch-9
Software engg. pressman_ch-9Dhairya Joshi
 
Design in construction
Design in constructionDesign in construction
Design in constructionAsha Sari
 
Design in construction
Design in constructionDesign in construction
Design in constructionAsha Sari
 
What is Software Engineering?
What is Software Engineering?What is Software Engineering?
What is Software Engineering?Russell Ovans
 

Similar to SE2018_Lec 18_ Design Principles and Design Patterns (20)

SE2_Lec 19_Design Principles and Design Patterns
SE2_Lec 19_Design Principles and Design PatternsSE2_Lec 19_Design Principles and Design Patterns
SE2_Lec 19_Design Principles and Design Patterns
 
Design final
Design finalDesign final
Design final
 
04 designing architectures
04 designing architectures04 designing architectures
04 designing architectures
 
Design concepts and principle,
Design concepts and principle, Design concepts and principle,
Design concepts and principle,
 
Function Oriented and Object Oriented Design,Modularization techniques
Function Oriented and Object Oriented Design,Modularization techniquesFunction Oriented and Object Oriented Design,Modularization techniques
Function Oriented and Object Oriented Design,Modularization techniques
 
UNIT3 PART2.pptx dhfdifhdsfvgudf dhfbdhbffdvf
UNIT3 PART2.pptx dhfdifhdsfvgudf dhfbdhbffdvfUNIT3 PART2.pptx dhfdifhdsfvgudf dhfbdhbffdvf
UNIT3 PART2.pptx dhfdifhdsfvgudf dhfbdhbffdvf
 
Devnology back toschool software reengineering
Devnology back toschool software reengineeringDevnology back toschool software reengineering
Devnology back toschool software reengineering
 
Excavating the knowledge of our ancestors
Excavating the knowledge of our ancestorsExcavating the knowledge of our ancestors
Excavating the knowledge of our ancestors
 
Unit 3
Unit 3Unit 3
Unit 3
 
Design concept -Software Engineering
Design concept -Software EngineeringDesign concept -Software Engineering
Design concept -Software Engineering
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Se ii unit2-software_design_principles
Se ii unit2-software_design_principlesSe ii unit2-software_design_principles
Se ii unit2-software_design_principles
 
Code Craftsmanship Checklist
Code Craftsmanship ChecklistCode Craftsmanship Checklist
Code Craftsmanship Checklist
 
OOSE Unit 4 PPT.ppt
OOSE Unit 4 PPT.pptOOSE Unit 4 PPT.ppt
OOSE Unit 4 PPT.ppt
 
Oose unit 4 ppt
Oose unit 4 pptOose unit 4 ppt
Oose unit 4 ppt
 
Software engg. pressman_ch-9
Software engg. pressman_ch-9Software engg. pressman_ch-9
Software engg. pressman_ch-9
 
Design in construction
Design in constructionDesign in construction
Design in construction
 
Design in construction
Design in constructionDesign in construction
Design in construction
 
What is Software Engineering?
What is Software Engineering?What is Software Engineering?
What is Software Engineering?
 
CHAPTER12.ppt
CHAPTER12.pptCHAPTER12.ppt
CHAPTER12.ppt
 

More from Amr E. Mohamed

Dsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processingDsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processingAmr E. Mohamed
 
Dcs lec03 - z-analysis of discrete time control systems
Dcs   lec03 - z-analysis of discrete time control systemsDcs   lec03 - z-analysis of discrete time control systems
Dcs lec03 - z-analysis of discrete time control systemsAmr E. Mohamed
 
Dcs lec02 - z-transform
Dcs   lec02 - z-transformDcs   lec02 - z-transform
Dcs lec02 - z-transformAmr E. Mohamed
 
Dcs lec01 - introduction to discrete-time control systems
Dcs   lec01 - introduction to discrete-time control systemsDcs   lec01 - introduction to discrete-time control systems
Dcs lec01 - introduction to discrete-time control systemsAmr E. Mohamed
 
DDSP_2018_FOEHU - Lec 10 - Digital Signal Processing Applications
DDSP_2018_FOEHU - Lec 10 - Digital Signal Processing ApplicationsDDSP_2018_FOEHU - Lec 10 - Digital Signal Processing Applications
DDSP_2018_FOEHU - Lec 10 - Digital Signal Processing ApplicationsAmr E. Mohamed
 
DSP_2018_FOEHU - Lec 07 - IIR Filter Design
DSP_2018_FOEHU - Lec 07 - IIR Filter DesignDSP_2018_FOEHU - Lec 07 - IIR Filter Design
DSP_2018_FOEHU - Lec 07 - IIR Filter DesignAmr E. Mohamed
 
DSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter DesignDSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter DesignAmr E. Mohamed
 
SE2018_Lec-22_-Continuous-Integration-Tools
SE2018_Lec-22_-Continuous-Integration-ToolsSE2018_Lec-22_-Continuous-Integration-Tools
SE2018_Lec-22_-Continuous-Integration-ToolsAmr E. Mohamed
 
SE2018_Lec 21_ Software Configuration Management (SCM)
SE2018_Lec 21_ Software Configuration Management (SCM)SE2018_Lec 21_ Software Configuration Management (SCM)
SE2018_Lec 21_ Software Configuration Management (SCM)Amr E. Mohamed
 
Selenium - Introduction
Selenium - IntroductionSelenium - Introduction
Selenium - IntroductionAmr E. Mohamed
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)Amr E. Mohamed
 
SE2018_Lec 19_ Software Testing
SE2018_Lec 19_ Software TestingSE2018_Lec 19_ Software Testing
SE2018_Lec 19_ Software TestingAmr E. Mohamed
 
DSP_2018_FOEHU - Lec 08 - The Discrete Fourier Transform
DSP_2018_FOEHU - Lec 08 - The Discrete Fourier TransformDSP_2018_FOEHU - Lec 08 - The Discrete Fourier Transform
DSP_2018_FOEHU - Lec 08 - The Discrete Fourier TransformAmr E. Mohamed
 
DSP_2018_FOEHU - Lec 05 - Digital Filters
DSP_2018_FOEHU - Lec 05 - Digital FiltersDSP_2018_FOEHU - Lec 05 - Digital Filters
DSP_2018_FOEHU - Lec 05 - Digital FiltersAmr E. Mohamed
 
DSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-TransformDSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-TransformAmr E. Mohamed
 
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and Systems
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and SystemsDSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and Systems
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and SystemsAmr E. Mohamed
 
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time SignalsDSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time SignalsAmr E. Mohamed
 
SE2018_Lec 15_ Software Design
SE2018_Lec 15_ Software DesignSE2018_Lec 15_ Software Design
SE2018_Lec 15_ Software DesignAmr E. Mohamed
 
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal Processing
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal ProcessingDSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal Processing
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal ProcessingAmr E. Mohamed
 

More from Amr E. Mohamed (20)

Dsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processingDsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processing
 
Dcs lec03 - z-analysis of discrete time control systems
Dcs   lec03 - z-analysis of discrete time control systemsDcs   lec03 - z-analysis of discrete time control systems
Dcs lec03 - z-analysis of discrete time control systems
 
Dcs lec02 - z-transform
Dcs   lec02 - z-transformDcs   lec02 - z-transform
Dcs lec02 - z-transform
 
Dcs lec01 - introduction to discrete-time control systems
Dcs   lec01 - introduction to discrete-time control systemsDcs   lec01 - introduction to discrete-time control systems
Dcs lec01 - introduction to discrete-time control systems
 
DDSP_2018_FOEHU - Lec 10 - Digital Signal Processing Applications
DDSP_2018_FOEHU - Lec 10 - Digital Signal Processing ApplicationsDDSP_2018_FOEHU - Lec 10 - Digital Signal Processing Applications
DDSP_2018_FOEHU - Lec 10 - Digital Signal Processing Applications
 
DSP_2018_FOEHU - Lec 07 - IIR Filter Design
DSP_2018_FOEHU - Lec 07 - IIR Filter DesignDSP_2018_FOEHU - Lec 07 - IIR Filter Design
DSP_2018_FOEHU - Lec 07 - IIR Filter Design
 
DSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter DesignDSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter Design
 
SE2018_Lec 17_ Coding
SE2018_Lec 17_ CodingSE2018_Lec 17_ Coding
SE2018_Lec 17_ Coding
 
SE2018_Lec-22_-Continuous-Integration-Tools
SE2018_Lec-22_-Continuous-Integration-ToolsSE2018_Lec-22_-Continuous-Integration-Tools
SE2018_Lec-22_-Continuous-Integration-Tools
 
SE2018_Lec 21_ Software Configuration Management (SCM)
SE2018_Lec 21_ Software Configuration Management (SCM)SE2018_Lec 21_ Software Configuration Management (SCM)
SE2018_Lec 21_ Software Configuration Management (SCM)
 
Selenium - Introduction
Selenium - IntroductionSelenium - Introduction
Selenium - Introduction
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
SE2018_Lec 19_ Software Testing
SE2018_Lec 19_ Software TestingSE2018_Lec 19_ Software Testing
SE2018_Lec 19_ Software Testing
 
DSP_2018_FOEHU - Lec 08 - The Discrete Fourier Transform
DSP_2018_FOEHU - Lec 08 - The Discrete Fourier TransformDSP_2018_FOEHU - Lec 08 - The Discrete Fourier Transform
DSP_2018_FOEHU - Lec 08 - The Discrete Fourier Transform
 
DSP_2018_FOEHU - Lec 05 - Digital Filters
DSP_2018_FOEHU - Lec 05 - Digital FiltersDSP_2018_FOEHU - Lec 05 - Digital Filters
DSP_2018_FOEHU - Lec 05 - Digital Filters
 
DSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-TransformDSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-Transform
 
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and Systems
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and SystemsDSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and Systems
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and Systems
 
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time SignalsDSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
 
SE2018_Lec 15_ Software Design
SE2018_Lec 15_ Software DesignSE2018_Lec 15_ Software Design
SE2018_Lec 15_ Software Design
 
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal Processing
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal ProcessingDSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal Processing
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal Processing
 

Recently uploaded

PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 

Recently uploaded (20)

PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 

SE2018_Lec 18_ Design Principles and Design Patterns

  • 2. 2  Design bridges that gap between knowing what is needed (software requirements specification) to entering the code that makes it work (the construction phase).  Design is both a verb and a noun.
  • 3. 3  During the design phase, software engineers apply their knowledge of the problem domain and implementation technologies in order to translate system specifications into plans for the technical implementation of the software.  The resulting design expresses the overall structure and organization of the planned implementation. It captures the essence of the solution independent of any implementation language.
  • 4. 4 There is a famous cartoon showing two professors at a chalkboard examining a proof that includes the step “then a miracle occurs”. At times it seems like this is the most that can be hoped for during software design.
  • 5. 5  There is a process for design but not an algorithm.  Software design is a heuristic rather than deterministic process.  No reliable process for conjuring up a design
  • 6. 6  Poorly designed programs are difficult to understand and modify.  The larger the program, the more pronounced are the consequences of poor design. Cost of adding the ith feature to a well-designed and poorly designed program
  • 7. 7  To better understand how good design can minimize technical complexity, it’s helpful to distinguish between two major types of complexity in software:  Essential complexities – complexities that are inherent in the problem.  Accidental/incidental complexities – complexities that are artifacts of the solution.  The total amount of complexity in a software solution is: ESSENTIAL COMPLEXITIES + ACCIDENTAL COMPLEXITIES
  • 8. 8  Design is the primary tool for managing essential and accidental complexities in software.  Good design doesn't reduce the total amount of essential complexity in a solution but it will reduce the amount of complexity that a programmer has to deal with at any one time.  A good design will manage essential complexities inherent in the problem without adding to accidental complexities consequential to the solution.
  • 9. 9  MODULARITY – subdivide the solution into smaller easier to manage components. (divide and conquer)  INFORMATION HIDING – hide details and complexity behind simple interfaces
  • 10. 10  ABSTRACTION – use abstractions to suppress details in places where they are unnecessary.  HIERARCHICAL ORGANIZATION – larger components may be composed of smaller components. Examples: a complex UI control such as tree control is a hierarchical organization of more primitive UI controls. A book outline represents the hierarchical organization of ideas.
  • 11. 11  Design is difficult because design is an abstraction of the solution which has yet to be created
  • 12. 12  The term wicked problem was first used to describe problems in social planning but engineers have recognized it aptly describes some of the problems they face as well.  A wicked problem is one that can only be clearly defined by solving it.  Need two solutions. The first to define the problem, and the second to solve it in the most efficient way.  Fred Brooks could have been talking about wicked problems when he advised: “Plan to throw one away; you will anyhow.”
  • 13. 13  Any product that is an aggregate of more primitive elements, can benefit from the activity of design.
  • 15. 15  Non-deterministic – A deterministic process is one that produces the same output given the same inputs. Design is non-deterministic. No two designers or design processes are likely to produce the same output.  Heuristic – because design is non-deterministic design techniques tend to rely on heuristics and rules-of-thumb rather than repeatable processes.  Emergent – the final design evolves from experience and feedback. Design is an iterative and incremental process where a complex system arises out of relatively simple interactions.
  • 16. 16  Good design reduces software complexity which makes the software easier to understand and modify. This facilitates rapid development during a project and provides the foundation for future maintenance and continued system evolution.  It enables reuse. Good design makes it easier to reuse code.  It improves software quality. Good design exposes defects and makes it easier to test the software.  Complexity is the root cause of other problems such as security. A program that is difficult to understand is more likely to be vulnerable to exploits than one that is simpler.
  • 17. 17 1. Understand the problem (software requirements). 2. Construct a “black-box” model of solution (system specification). System specifications are typically represented with use cases (especially when doing OOD). 3. Look for existing solutions (e.g. architecture and design patterns) that cover some or all of the software design problems identified. 4. Design not complete? Consider using one or more design techniques to discover missing design elements  Noun-verb analysis, CRC Cards, step-wise refinement, etc.  Take final analysis model and pronounce a first-draft design (solution) model 5. Consider building prototypes 6. Document and review design 7. Iterate over solution (Refactor) (Evolve the design until it meets functional requirements and maximizes non-functional requirements)
  • 18. 18  User requirements and system specification (including any constraints on design and implementation options)  Domain knowledge (For example, if it’s a healthcare application the designer will need some knowledge of healthcare terms and concepts.)  Implementation knowledge (capabilities and limitations of eventual execution environment)
  • 19. 19  Patterns play an important role in the design methods of today
  • 20. 20  Methods and patterns are the principle techniques for dealing with the challenges of design  They are useful for:  Creating a design  Documenting and communicating a design  Transferring design knowledge and experience between practitioners
  • 21. 21  A design pattern is a reusable solution to a commonly occurring design problem  Design patterns are adapted for the unique characteristics of the particular problem  Just as there are levels of design, there are levels of design patterns:  Architecture Styles/Patterns  Design Patterns  Programming Idioms
  • 22. 22
  • 23. 23  Robert Martin  "AGILE SOFTWARE DEVELOPMENT: PRINCIPLES, PATTERNS, AND PRACTICES“  “CLEAN CODE”
  • 24. 24  Design is generally “THE DECISIONS WE TAKE TO BUILD SOMETHING”  Design + implementation = Product  If we apply this to software: DESIGN + PROGRAMMING / CODING = SOFTWARE PRODUCT
  • 26. 26 if CHANGE is The only constant in software Then MODIFIABILITY Is a vital design consideration
  • 27. 27  Increased difficulty to adapt and maintain  Causes  Communication/Documentation breakdown • Maintainers not fully familiar with the original design principles -> change works, but…  Design is not resilient in the face of change
  • 28. 28  Characteristics of a bad design:  RIGIDITY - It is hard to change because every change affects too many other parts of the system.  FRAGILITY - When you make a change, unexpected parts of the system break.  IMMOBILITY - It is hard to reuse in another application because it cannot be disentangled from the current application.  VISCOSITY: The law of least resistance when faced with a choice • Design viscosity: Hacks are easier/faster than preserving the design • Environment viscosity: Slow cycle time -> fastest choice
  • 29. 29  SOLID  Single Responsibility Principle  Open Closed Principle  Liskov Substitution Principle  Interface Segregation Principle  Dependency Inverison Principle  Code becomes more Testably (remember TDD is not only about testing, more important its about Design)
  • 30. 30  "There should never be more than one reason for a class to change." — Robert Martin, SRP paper linked from The Principles of OOD  My translation: A class should concentrate on doing one thing and one thing only
  • 31. 31  Two resposibilities  Connection Management + Data Communication interface Modem { public void dial(String pno); public void hangup(); public void send(char c); public char recv(); }
  • 32. 32  Separate into two interfaces interface DataChannel { public void send(char c); public char recv(); } interface Connection { public void dial(String phn); public char hangup(); }
  • 33. 33  "Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification." — Robert Martin paraphrasing Bertrand Meyer, OCP paper linked from The Principles of OOD  My translation: Change a class' behavior using inheritance and composition
  • 34. 34 // Open-Close Principle - Bad example class GraphicEditor { public void drawShape(Shape s) { if (s.m_type==1) drawRectangle(s); else if (s.m_type==2) drawCircle(s); } public void drawCircle(Circle r) {....} public void drawRectangle(Rectangle r) {....} } class Shape { int m_type; } class Rectangle extends Shape { Rectangle() { super.m_type=1; } } class Circle extends Shape { Circle() { super.m_type=2; } }
  • 35. 35  Impossible to add a new Shape without modifying GraphEditor  Important to understand GraphEditor to add a new Shape  Tight coupling between GraphEditor and Shape  Difficult to test a specific Shape without involving GraphEditor  If-Else-/Case should be avoided
  • 36. 36 // Open-Close Principle - Good example class GraphicEditor { public void drawShape(Shape s) { s.draw(); } } class Shape { //super class abstract void draw(); } class Rectangle extends Shape { public void draw() { // draw the rectangle } }
  • 37. 37  "Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it." — Robert Martin, LSP paper linked from The Principles of OOD.  My translation: Subclasses should behave nicely when used in place of their base class
  • 38. 38 // Violation of Liskov's Substitution Principle class Rectangle { int m_width; int m_height; public void setWidth(int width){ m_width = width; } public void setHeight(int ht){ m_height = ht; } public int getWidth(){ return m_width; } public int getHeight(){ return m_height; } public int getArea(){ return m_width * m_height; } } class Square extends Rectangle { public void setWidth(int width){ m_width = width; m_height = width; } public void setHeight(int height){ m_width = height; m_height = height; } }
  • 39. 39 class LspTest { private static Rectangle getNewRectangle() { // it can be an object returned by some factory ... return new Square(); } public static void main (String args[]) { Rectangle r = LspTest.getNewRectangle(); r.setWidth(5); r.setHeight(10); // user knows that r it's a rectangle. It assumes that he's able to set the width and height as for the base class System.out.println(r.getArea()); // now he's surprised to see that the area is 100 instead of 50. } }
  • 40. 40  "Clients should not be forced to depend upon interfaces that they do not use." — Robert Martin, ISP paper linked from The Principles of OOD  My translation: Keep interfaces small
  • 41. 41  Don’t force classes so implement methods they can’t (Swing/Java)  Don’t pollute interfaces with a lot of methods  Avoid ’fat’ interfaces
  • 42. 42 //bad example (polluted interface) interface Worker { void work(); void eat(); } ManWorker implements Worker { void work() {…}; void eat() {30 min break;}; } RobotWorker implements Worker { void work() {…}; void eat() {//Not Appliciable for a RobotWorker}; }
  • 43. 43  Solution - split into two interfaces interface Workable { public void work(); } interface Feedable{ public void eat(); }
  • 44. 44  "A. High level modules should not depend upon low level modules. Both should depend upon abstractions. B. Abstractions should not depend upon details. Details should depend upon abstractions." — Robert Martin, DIP paper linked from The Principles of OOD  My translation: Use lots of interfaces and abstractions
  • 45. 45 //DIP - bad example public class EmployeeService { private EmployeeFinder emFinder //concrete class, not abstract. Can access a SQL DB for instance public Employee findEmployee(…) { emFinder.findEmployee(…) } }
  • 46. 46  Now its possible to change the finder to be a XmlEmployeeFinder, DBEmployeeFinder, FlatFileEmployeeFinder, MockEmployeeFinder…. //DIP - fixed public class EmployeeService { private IEmployeeFinder emFinder //depends on an abstraction, no an implementation public Employee findEmployee(…) { emFinder.findEmployee(…) } }
  • 48. 48
  • 49. 49  In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design.  A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.
  • 50. 50  A design pattern  Design Patterns are time-tested common solutions to recurring design problems.  Are the answer to a question that commonly arises “How can I … ?”  Abstracts a recurring design structure  Comprises class and/or object • Dependencies • Structures • Interactions • Conventions  Names & specifies the design structure explicitly  Distils design experience
  • 51. 51
  • 52. 52  Can reuse solutions  Gives us a head start (mostly design, but implementation too)  Avoids unanticipated results as we are using time-tested solutions  No need to reinvent the wheel  Establish common terminology  Design patterns provide a common point of reference
  • 53. 53  Design patterns gained popularity in computer science after a certain book was published in 1994 by four authors, commonly know as Gang of Four or GOF  Gang of Four (GoF) Gamma, Helm, Johnson, Vlissides, - founders of movement.  Gamma et al, Design Patterns: Elements of Reusable Object-Oriented Software, Addison Wesley, 1995.  They offer advice and help for developing quality software  An object-oriented design pattern systematically names, explains and evaluates an important and recurring design in object- oriented systems.
  • 54. 54  A design pattern has 4 basic parts: 1. Pattern Name 2. Problem 3. Solution 4. Consequences and trade-offs of application  Language- and implementation-independent  A “micro-architecture”  Adjunct to existing methodologies (Unified, OMT, etc.)  No mechanical application  The solution needs to be translated into concrete terms in the application context by the developer
  • 55. 55  Codify good design  Distil and disseminate experience  Aid to novices and experts alike  Abstract how to think about design  Give design structures explicit names  Common vocabulary  Reduced complexity  Greater expressiveness  Capture and preserve design information  Articulate design decisions succinctly  Improve documentation  Facilitate restructuring/refactoring  Patterns are interrelated  Additional flexibility
  • 57. 57  Ensure a class only has one instance, and provide a global point of access to it. Singleton
  • 58. 58  Motivation  How to cleanly provide access to a global variable?  Structure  Output
  • 59. 59  There must be exactly one instance of a class, and it must be accessible to clients from a well-known access point.  When the sole instance should be extensible by subclassing, and clients should be able to use an extended instance without modifying their code.
  • 60. 60  Controlled access to sole instance.  Reduced name space.  Permits refinement of operations and representation  Permits a variable number of instances.
  • 61. 61 Hayes Modem USR Modem Zoom Modem Modem < ? > File Sync Dedicated Modem Send () Receive() Dial () {} Hangup () {} Send () Receive() Dial () Hangup ()
  • 62. 62 Hayes Modem USR Modem Zoom Modem Modem File Sync Send () Receive() Dial () Hangup () Dedicated Modem Send () Receive() Dedicated Modem Adapter Send () Receive() Dial () {} Hangup () {}
  • 63. ADAPTER (wrapper) Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
  • 64. 64  Motivation:  Reuse of existing codebase in a situation that it did not anticipate.  structure:
  • 65. 65  Applicability:  You want to use an existing class, and its interface does not match the one you need  Consequences:  The amount of adapting is needed  Conceptual distance between adapter and adaptee can cause undesirable side effects
  • 66.
  • 67. Observer (Publish-Subscribe) Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
  • 68. 68  Motivation:  Maintain consistency between collaborating objects while maintaining loose coupling  Structure:
  • 69. 69  Applicability:  When an abstraction has two aspects, one dependent on the other.  When a change to one object requires changing others, and you don't know how many objects need to be changed.  When an object should be able to notify other objects without making assumptions about who these objects are.  Consequences:  Abstract coupling between Subject and Observer  Support for broadcast communication  Unexpected updates  Dangling References  Memory Issues
  • 70. 70