Date post: | 07-May-2015 |
Category: |
Technology |
Upload: | confiz |
View: | 1,508 times |
Download: | 1 times |
Boutique product development company It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
Boutique product development company It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
SOLID Principles of OO Design Waleed Bin Dawood | Software Engineer
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand" Martin Fowler
SOLID Principles of Object Oriented Design
● Software design
● What makes a design good or bad ?
● Design/Code Smells
● SOLID Principles
Waleed Bin Dawood | Software Engineer
SOLID Principles
What is software design ?
Waleed Bin Dawood | Software Engineer
• The source code is the design
• UML diagram represents part of a design
• Software design process includes coding, testing,
refactoring…
• The programmer is the actual software designer.
SOLID Principles
Why do we need a good design ?
Waleed Bin Dawood | Software Engineer
• To deliver fast
• To manage change easily
• To deal with complexity
SOLID Principles
How to identify a bad design ?
Waleed Bin Dawood | Software Engineer
But may be we need some better criteria :)
“In my BillG review meeting, the whole
reporting hierarchy was there...and a
person...whose whole job during the
meeting was to keep an accurate
count of how many times Bill said the F
word. The lower the f***-count, the
better.”
-- Joel Spolsky, My First BillG Review
SOLID Principles
How to identify a bad design ?
Waleed Bin Dawood | Software Engineer
Design/Code Smells
● Rigidity - The design is hard to change
● Fragility - The design is easy to break
● Immobility - The design is hard to reuse
● Viscosity - It is hard to do the right thing
SOLID Principles
Good design
Waleed Bin Dawood | Software Engineer
How to achieve a good design ?
• Follow programming practices of your
language/framework
• Follow OO design principles
• Use design patterns
What are the characteristics of a good design ?
● High Cohesion
● Low Coupling
SOLID Principles
Let’s go SOLID
Waleed Bin Dawood | Software Engineer
Initial Stands for
(acronym) Concept
S SRP Single responsibility principle
a class should have only a single responsibility.
O OCP Open/closed principle
“software entities … should be open for extension, but closed for modification”.
L LSP Liskov substitution principle
“objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program”.
I ISP Interface segregation principle
“many client-specific interfaces are better than one general-purpose interface.”
D DIP Dependency inversion principle
one should “Depend upon Abstractions. Do not depend upon concretions.”
SOLID Principles
Single Responsibility Principle
Waleed Bin Dawood | Software Engineer
• “There should never be more than one reason for a class
to change.” -- Robert Martin, SRP paper
• Easier : A class should concentrate on doing one thing
and one thing only
• It give you high cohesion
• It’s often hard to identify different responsibilities
SOLID Principles
Single Responsibility Principle
Waleed Bin Dawood | Software Engineer
• Is SRP violated here ?
• Two responsibilities:
o Connection management
o Data Communication
SOLID Principles
Single Responsibility Principle
Waleed Bin Dawood | Software Engineer
• Solution :
• Two responsibilities:
o Connection management
o Data Communication
SOLID Principles
Open/Closed Principle
Waleed Bin Dawood | Software Engineer
• “Software entities should be open for extension, but
closed for modification.” -- Robert Martin paraphrasing
Bertrand Meyer, OCP Paper
• Easier : you should be able to extend the behaviour of a
module without changing it
• Abstraction is the key
SOLID Principles
Open/Closed Principle
Waleed Bin Dawood | Software Engineer
• Is OCP violated here ?
SOLID Principles
Open/Closed Principle
Waleed Bin Dawood | Software Engineer
• Solution:
SOLID Principles
Liskov Substitution Principle
Waleed Bin Dawood | Software Engineer
• “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
• Easier : Subclasses should behave nicely when used in
place of their parent class
SOLID Principles
Liskov Substitution Principle
Waleed Bin Dawood | Software Engineer
• How would you model the relationship between a square
and a rectangle ?
• Should the square class extends rectangle ?
• Many of you would say “yes” or “why not”. Square is a
kind of Rectangle after all. An obvious IS-A relationship
• Issues in this Approach:
o Square has unnecessary attribute ‘width’
o What happens when we want to calculate area ?
o What happens if the client code is assuming height
and width to be independent of each other
SOLID Principles
Dependency Inversion Principle
Waleed Bin Dawood | Software Engineer
• “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
• Easier:
o Use lot of interfaces (program to interface)
o Use abstractions
SOLID Principles
Interface Segregation Principle
Waleed Bin Dawood | Software Engineer
• “Clients should not be forced interfaces that they do not
use.”-- Robert Martin, ISP paper
• Easier : avoid fat interfaces (cohesion)
Human Computer Interaction
Thank you for your time
Waleed Bin Dawood | Software Engineer
If you have any questions,
please ask now or forever
hold your peace
Human Computer Interaction
References
Waleed Bin Dawood | Software Engineer
• http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
• http://www.slideshare.net/bbossola/geecon09-solid
• http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
• http://www.slideshare.net/intellizhang/the-oo-design-principles
• http://www.slideshare.net/enbohm/solid-design-principles-9016117
• http://www.oodesign.com/design-principles.html
• http://objectmentor.com/resources/publishedArticles.html