SlideShare a Scribd company logo
Improving Software Quality Using
Object Oriented Design Principles
By
Dr. Syed Hassan Amin
Note : Thanks to all those who contributed to creating and improving
these slides.
High Level Overview
• Software Quality
• OOP Design Principles
• OO Best Practices
• Bad Smells of Code
• Details of various principles with examples
• Note : We will not be able to cover everything in this lecture !
Introduction
• In software engineering we normally start with requirement
gathering, analysis, writing features list and design
• At some point you actually are going to write some code.
• And that’s where design principles come into play
Software Quality
• Software quality refers to two related but distinct notions that exist
wherever quality is defined in a business context:-
• Software functional quality reflects how well it complies with or
conforms to a given design, based on functional requirements or
specifications.
• Software structural quality refers to how it meets non-functional
requirements that support the delivery of the functional
requirements, such as robustness or maintainability, the degree to
which the software was produced correctly.
• Properties/Characteristics of software that constitute software
quality are :-
• Flexibility
• Maintainability
• Extendibility
• Reusability
• Testability
What is OO Design Principle?
• A design principle is a basic tool or technique that can be
applied to writing code to make resultant software
maintainable, flexible, extendible and reusable.
• Today we are going to look into some design principles
that people came up with over the years and how they
can make you a better engineer.
• Put aside your thoughts of “doing it your way”; this
presentation is about doing it the smarter and faster way.
OOP Design Principles
• Encapsulation or Information Hiding
• Open-Closed principle(OCP)
• Single responsibility principle(SRP)
• Liskov substitution principle(LSP)
• Don’t repeat yourself(DRY)
• Law of Demeter(LoD)
• Dependency Injection or Inversion of Control(IoC)
OO Best Practices
• Encapsulate what varies
• Code to an interface rather than to an implementation
• Dependency Injection
• Composition better than Inheritance
• Prefer ‘Has a’ over Ís a’
• Use Inheritance Sparingly
• Reduce Coupling, Increase Cohesion
• Classes are about Behavior i.e. No Dumb Data Holders
Bad Smells of Code
• Repeated Code
• Long Method
• Long Class
• Long Parameter List
• Data Class – Dumb Data Holder
• Violation of encapsulation
• Global variable(s)
Open-Close Principle
“Classes should be open for extension, and closed for
modification”
• New functionality should be added with minimum changes in
the existing code.
• The design should be done in a way to allow the adding of
new functionality as new classes, keeping existing code
unchanged.
OCP - Bad Example
OCP – Bad Example
OCP – Good Example
OCP – Good Example
Like every principle OCP is only a principle. Making a flexible design involves
additional time and effort ,and it introduce new level of abstraction increasing the
complexity of the code.
So this principle should be applied in those areas which are most likely to be
changed.
Single Responsibility
Principle(SRP)
“A class should have only one reason to change”
• This principle states that if we have 2 reasons to change for a
class, we have to split the functionality in two classes.
• Each class will handle only one responsibility and in the future
if we need to make one change we are going to make it in the
class which handle it.
• When we need to make a change in a class having more
responsibilities the change might effect the other functionality
of the classes.
Single Responsibility Principle
Is this qualify Single Responsibility Principle (SRP) ?
SRP Spottingmultipleresponsibilities
Liskov Substitution
Principle(LSP)
“Sub Type must be substitutable for their base type”
• We must make sure that the new derived classes just extend
without replacing the functionality of base classes.
• Liskov’s substitution principle states that if a program module
is using a base class, then the reference to the base class can
be replaced with a derived class without affecting the
functionality of the program module.
LSP – Bad Example
• Extend Board to produce 3D
board
• Analyze the design to find out
design problems
• This Principle is just an extension
of Open-Close Principle
• The focus of this principle is to
make sure that new derived
classes are extending the base
class without changing their
behavior
LSP – Bad Example
• But this means that an instance of Board3D looks like this:
• Each attribute and method in bold is meaningless in this object
• Board3D is getting nothing useful from Board except for width
and height
• We certainly could NOT create a Board3D object and hand it to
code expecting a Board object!
• As a result, this design violates the
LSP principle
LSP – Delegation comes to
rescue
• Board3D example violated LSP because of inappropriate use of
inheritance.
• Thus, if you need to use functionality in another class, but you
don’t want to change that functionality, consider using
delegation instead of inheritance
• Inheritance was simply the wrong way to gain access to the
Board’s functionality
• Delegation is when you hand over the responsibility for a
particular task to some other class or method
LSP – Delegation comes to
rescue (Cont’d)
• Board3D now maintains a
list of Board objects for
each legal value of “zpos”
• It then delegates to the
Board object to handle
the requested service
public Tile getTile(int x, int
y, int z) {
Board b = boards.get(z);
return b.getTile(x,y);
}
Don’t Repeat Yourself (DRY)
“Avoid duplicate code by abstracting out things that are
common and putting these in a single location”
DRY is about having each piece of information and behavior in
your system in a single sensible place.
DRY – Bad Example
DRY – Correcting Bad Example
1- Let’s abstract out the common code
DRY – Correcting Bad Example
2- Now remove the code from other locations
That’s it! 
Encapsulate What Varies
• Anytime you have behavior in an application that you think is likely
to change, you want to move that behavior away from parts of
your application that probably won’t change very frequently.
• In other words you should always try to encapsulate what varies.
EWV- Example
It helps protect your classes from unnecessary changes.
Code To An Interface Principle
“Code to an interface rather than to an implementation”
• Coding to an interface, rather than to an implementation
makes your software easier to extend and reuse
• Objective is to hide implementation details thus reducing
coupling and increasing cohesion
• Any time you are writing code that interact with other classes,
you have two choices.
• You can write code that interact directly with sub class, Like
BaseballPlayer, or you can write code that interact with Athlete.
• When you run into the choice like this, you should always favor
coding to the interface, not to the implementation.
Code To Interface… Example
Use Inheritance Sparingly
• Rule of thumb : (almost)
• Inherit only when clear ‘is a’ relation exists AND
• All the members in base Class will be used/implemented in sub
classes
• If you use inheritance other than these rules, highly probably
you are mistaken
Inappropriate use
• Board3D is not a Board2D
• Board3D will have useless members eventually,
like tiles : int[][]
• All the methods of Board2D will become useless
in Board3D
• Inheritance is surely not the option
Solution
• Board3D is composed of Board2D
• We have “depth” times Board2Ds in our Board3D class
• All the operations are delegated to Board2D methods
• Board3D methods will use respective Board2D methods for “depth” times
• Composition and delegation is better choice
Summary
We have covered some basic object oriented design principles
that help us to write the code which is more maintainable and
extensible.
Following are some more principles which you can see by
yourself
• Dependency Injection Principle
• Favor Composition Over Inheritance
References
• http://www.oodesign.com/design-principles.html
• http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
• Head First Object Oriented Analysis and Design (O’Reilly)
Ad

More Related Content

What's hot (20)

Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in java
Tech_MX
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
Haitham El-Ghareeb
 
Unit 5
Unit 5Unit 5
Unit 5
gopal10scs185
 
UML (Unified Modeling Language)
UML (Unified Modeling Language)UML (Unified Modeling Language)
UML (Unified Modeling Language)
Nguyen Tuan
 
Chapter 5 software design
Chapter 5 software designChapter 5 software design
Chapter 5 software design
Piyush Gogia
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 
10 component diagram
10 component diagram10 component diagram
10 component diagram
Baskarkncet
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
Data visualisation laboratory report/manual
Data visualisation laboratory report/manualData visualisation laboratory report/manual
Data visualisation laboratory report/manual
VidhyambikaSR
 
Major and Minor Elements of Object Model
Major and Minor Elements of Object ModelMajor and Minor Elements of Object Model
Major and Minor Elements of Object Model
sohailsaif
 
Object Oriented Design Concept
Object Oriented Design ConceptObject Oriented Design Concept
Object Oriented Design Concept
Sharath g
 
Object and class relationships
Object and class relationshipsObject and class relationships
Object and class relationships
Pooja mittal
 
Introduction to multiple object tracking
Introduction to multiple object trackingIntroduction to multiple object tracking
Introduction to multiple object tracking
Fan Yang
 
Staruml
StarumlStaruml
Staruml
valeri kopaleishvili
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
Siva Sathya
 
Object Size Detector - Computer Vision
Object Size Detector - Computer VisionObject Size Detector - Computer Vision
Object Size Detector - Computer Vision
Shyama Bhuvanendran
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
kirupasuchi1996
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
Rome468
 
Object diagram
Object diagramObject diagram
Object diagram
Preeti Mishra
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
Acp Jamod
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in java
Tech_MX
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
Haitham El-Ghareeb
 
UML (Unified Modeling Language)
UML (Unified Modeling Language)UML (Unified Modeling Language)
UML (Unified Modeling Language)
Nguyen Tuan
 
Chapter 5 software design
Chapter 5 software designChapter 5 software design
Chapter 5 software design
Piyush Gogia
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 
10 component diagram
10 component diagram10 component diagram
10 component diagram
Baskarkncet
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
Data visualisation laboratory report/manual
Data visualisation laboratory report/manualData visualisation laboratory report/manual
Data visualisation laboratory report/manual
VidhyambikaSR
 
Major and Minor Elements of Object Model
Major and Minor Elements of Object ModelMajor and Minor Elements of Object Model
Major and Minor Elements of Object Model
sohailsaif
 
Object Oriented Design Concept
Object Oriented Design ConceptObject Oriented Design Concept
Object Oriented Design Concept
Sharath g
 
Object and class relationships
Object and class relationshipsObject and class relationships
Object and class relationships
Pooja mittal
 
Introduction to multiple object tracking
Introduction to multiple object trackingIntroduction to multiple object tracking
Introduction to multiple object tracking
Fan Yang
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
Siva Sathya
 
Object Size Detector - Computer Vision
Object Size Detector - Computer VisionObject Size Detector - Computer Vision
Object Size Detector - Computer Vision
Shyama Bhuvanendran
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
Rome468
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
Acp Jamod
 

Viewers also liked (13)

Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
deonpmeyer
 
S.O.L.I.D. Software-Engineering Principles - a must know for developers
S.O.L.I.D. Software-Engineering Principles - a must know for developersS.O.L.I.D. Software-Engineering Principles - a must know for developers
S.O.L.I.D. Software-Engineering Principles - a must know for developers
Prof. Dr. Roland Petrasch
 
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO ProprietySOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
Chris Weldon
 
bGenius kennissessie_20120510
bGenius kennissessie_20120510bGenius kennissessie_20120510
bGenius kennissessie_20120510
bgenius
 
Rupicon 2014 solid
Rupicon 2014 solidRupicon 2014 solid
Rupicon 2014 solid
rupicon
 
Beyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO codeBeyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO code
Matthias Noback
 
SOLID Design principles
SOLID Design principlesSOLID Design principles
SOLID Design principles
Mohamed Sanaulla
 
OOD Principles and Patterns
OOD Principles and PatternsOOD Principles and Patterns
OOD Principles and Patterns
Nguyen Tung
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
Julie Iskander
 
Applying OO Concepts
Applying OO ConceptsApplying OO Concepts
Applying OO Concepts
Mohammed Irfan Shaikh
 
Advanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, IdiomsAdvanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, Idioms
Clint Edmonson
 
OOP programming
OOP programmingOOP programming
OOP programming
anhdbh
 
C# OOP Advanced Concepts
C# OOP Advanced ConceptsC# OOP Advanced Concepts
C# OOP Advanced Concepts
agni_agbc
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
deonpmeyer
 
S.O.L.I.D. Software-Engineering Principles - a must know for developers
S.O.L.I.D. Software-Engineering Principles - a must know for developersS.O.L.I.D. Software-Engineering Principles - a must know for developers
S.O.L.I.D. Software-Engineering Principles - a must know for developers
Prof. Dr. Roland Petrasch
 
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO ProprietySOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
Chris Weldon
 
bGenius kennissessie_20120510
bGenius kennissessie_20120510bGenius kennissessie_20120510
bGenius kennissessie_20120510
bgenius
 
Rupicon 2014 solid
Rupicon 2014 solidRupicon 2014 solid
Rupicon 2014 solid
rupicon
 
Beyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO codeBeyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO code
Matthias Noback
 
OOD Principles and Patterns
OOD Principles and PatternsOOD Principles and Patterns
OOD Principles and Patterns
Nguyen Tung
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
Julie Iskander
 
Advanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, IdiomsAdvanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, Idioms
Clint Edmonson
 
OOP programming
OOP programmingOOP programming
OOP programming
anhdbh
 
C# OOP Advanced Concepts
C# OOP Advanced ConceptsC# OOP Advanced Concepts
C# OOP Advanced Concepts
agni_agbc
 
Ad

Similar to Improving Software Quality Using Object Oriented Design Principles (20)

Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
Alfred Jett Grandeza
 
Solid principles
Solid principlesSolid principles
Solid principles
Kumaresh Chandra Baruri
 
Is your code SOLID enough?
 Is your code SOLID enough? Is your code SOLID enough?
Is your code SOLID enough?
SARCCOM
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
Amr Abd El Latief
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
Metin Ogurlu
 
The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
Bill Buchan
 
Clean code
Clean codeClean code
Clean code
Simon Sönnby
 
Software design principles
Software design principlesSoftware design principles
Software design principles
Md.Mojibul Hoque
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patterns
Rahul Singh
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
Bhavin Gandhi
 
Software Design
Software DesignSoftware Design
Software Design
Ahmed Misbah
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
Juggernaut Liu
 
Design Patterns .Net
Design Patterns .NetDesign Patterns .Net
Design Patterns .Net
Hariom Shah
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
Benjamin Baumann
 
SOLID_Principles_Explained_Presentation.pptx
SOLID_Principles_Explained_Presentation.pptxSOLID_Principles_Explained_Presentation.pptx
SOLID_Principles_Explained_Presentation.pptx
SahanaRV2
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
Knoldus Inc.
 
Introduction
IntroductionIntroduction
Introduction
Preeti Mishra
 
Solid principes
Solid principesSolid principes
Solid principes
Steven Ndaye
 
android principle.pptx
android principle.pptxandroid principle.pptx
android principle.pptx
debasish duarah
 
Is your code SOLID enough?
 Is your code SOLID enough? Is your code SOLID enough?
Is your code SOLID enough?
SARCCOM
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
Metin Ogurlu
 
The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
Bill Buchan
 
Software design principles
Software design principlesSoftware design principles
Software design principles
Md.Mojibul Hoque
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patterns
Rahul Singh
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
Bhavin Gandhi
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
Juggernaut Liu
 
Design Patterns .Net
Design Patterns .NetDesign Patterns .Net
Design Patterns .Net
Hariom Shah
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
 
SOLID_Principles_Explained_Presentation.pptx
SOLID_Principles_Explained_Presentation.pptxSOLID_Principles_Explained_Presentation.pptx
SOLID_Principles_Explained_Presentation.pptx
SahanaRV2
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
Knoldus Inc.
 
Ad

More from Dr. Syed Hassan Amin (12)

Greenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparisonGreenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparison
Dr. Syed Hassan Amin
 
Introduction To Docker
Introduction To  DockerIntroduction To  Docker
Introduction To Docker
Dr. Syed Hassan Amin
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
Dr. Syed Hassan Amin
 
Multitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq RecognitionMultitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq Recognition
Dr. Syed Hassan Amin
 
Understandig PCA and LDA
Understandig PCA and LDAUnderstandig PCA and LDA
Understandig PCA and LDA
Dr. Syed Hassan Amin
 
Agile Scrum Methodology
Agile Scrum MethodologyAgile Scrum Methodology
Agile Scrum Methodology
Dr. Syed Hassan Amin
 
Thin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better CodeThin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better Code
Dr. Syed Hassan Amin
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
Dr. Syed Hassan Amin
 
Software Project Management Tips and Tricks
Software Project Management Tips and TricksSoftware Project Management Tips and Tricks
Software Project Management Tips and Tricks
Dr. Syed Hassan Amin
 
Learning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve JobsLearning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve Jobs
Dr. Syed Hassan Amin
 
Understanding and Managing Technical Debt
Understanding and Managing Technical DebtUnderstanding and Managing Technical Debt
Understanding and Managing Technical Debt
Dr. Syed Hassan Amin
 
An OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq FontAn OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq Font
Dr. Syed Hassan Amin
 
Greenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparisonGreenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparison
Dr. Syed Hassan Amin
 
Multitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq RecognitionMultitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq Recognition
Dr. Syed Hassan Amin
 
Thin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better CodeThin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better Code
Dr. Syed Hassan Amin
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
Dr. Syed Hassan Amin
 
Software Project Management Tips and Tricks
Software Project Management Tips and TricksSoftware Project Management Tips and Tricks
Software Project Management Tips and Tricks
Dr. Syed Hassan Amin
 
Learning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve JobsLearning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve Jobs
Dr. Syed Hassan Amin
 
Understanding and Managing Technical Debt
Understanding and Managing Technical DebtUnderstanding and Managing Technical Debt
Understanding and Managing Technical Debt
Dr. Syed Hassan Amin
 
An OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq FontAn OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq Font
Dr. Syed Hassan Amin
 

Recently uploaded (20)

Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 

Improving Software Quality Using Object Oriented Design Principles

  • 1. Improving Software Quality Using Object Oriented Design Principles By Dr. Syed Hassan Amin Note : Thanks to all those who contributed to creating and improving these slides.
  • 2. High Level Overview • Software Quality • OOP Design Principles • OO Best Practices • Bad Smells of Code • Details of various principles with examples • Note : We will not be able to cover everything in this lecture !
  • 3. Introduction • In software engineering we normally start with requirement gathering, analysis, writing features list and design • At some point you actually are going to write some code. • And that’s where design principles come into play
  • 4. Software Quality • Software quality refers to two related but distinct notions that exist wherever quality is defined in a business context:- • Software functional quality reflects how well it complies with or conforms to a given design, based on functional requirements or specifications. • Software structural quality refers to how it meets non-functional requirements that support the delivery of the functional requirements, such as robustness or maintainability, the degree to which the software was produced correctly. • Properties/Characteristics of software that constitute software quality are :- • Flexibility • Maintainability • Extendibility • Reusability • Testability
  • 5. What is OO Design Principle? • A design principle is a basic tool or technique that can be applied to writing code to make resultant software maintainable, flexible, extendible and reusable. • Today we are going to look into some design principles that people came up with over the years and how they can make you a better engineer. • Put aside your thoughts of “doing it your way”; this presentation is about doing it the smarter and faster way.
  • 6. OOP Design Principles • Encapsulation or Information Hiding • Open-Closed principle(OCP) • Single responsibility principle(SRP) • Liskov substitution principle(LSP) • Don’t repeat yourself(DRY) • Law of Demeter(LoD) • Dependency Injection or Inversion of Control(IoC)
  • 7. OO Best Practices • Encapsulate what varies • Code to an interface rather than to an implementation • Dependency Injection • Composition better than Inheritance • Prefer ‘Has a’ over Ís a’ • Use Inheritance Sparingly • Reduce Coupling, Increase Cohesion • Classes are about Behavior i.e. No Dumb Data Holders
  • 8. Bad Smells of Code • Repeated Code • Long Method • Long Class • Long Parameter List • Data Class – Dumb Data Holder • Violation of encapsulation • Global variable(s)
  • 9. Open-Close Principle “Classes should be open for extension, and closed for modification” • New functionality should be added with minimum changes in the existing code. • The design should be done in a way to allow the adding of new functionality as new classes, keeping existing code unchanged.
  • 10. OCP - Bad Example
  • 11. OCP – Bad Example
  • 12. OCP – Good Example
  • 13. OCP – Good Example Like every principle OCP is only a principle. Making a flexible design involves additional time and effort ,and it introduce new level of abstraction increasing the complexity of the code. So this principle should be applied in those areas which are most likely to be changed.
  • 14. Single Responsibility Principle(SRP) “A class should have only one reason to change” • This principle states that if we have 2 reasons to change for a class, we have to split the functionality in two classes. • Each class will handle only one responsibility and in the future if we need to make one change we are going to make it in the class which handle it. • When we need to make a change in a class having more responsibilities the change might effect the other functionality of the classes.
  • 15. Single Responsibility Principle Is this qualify Single Responsibility Principle (SRP) ?
  • 17. Liskov Substitution Principle(LSP) “Sub Type must be substitutable for their base type” • We must make sure that the new derived classes just extend without replacing the functionality of base classes. • Liskov’s substitution principle states that if a program module is using a base class, then the reference to the base class can be replaced with a derived class without affecting the functionality of the program module.
  • 18. LSP – Bad Example • Extend Board to produce 3D board • Analyze the design to find out design problems • This Principle is just an extension of Open-Close Principle • The focus of this principle is to make sure that new derived classes are extending the base class without changing their behavior
  • 19. LSP – Bad Example • But this means that an instance of Board3D looks like this: • Each attribute and method in bold is meaningless in this object • Board3D is getting nothing useful from Board except for width and height • We certainly could NOT create a Board3D object and hand it to code expecting a Board object! • As a result, this design violates the LSP principle
  • 20. LSP – Delegation comes to rescue • Board3D example violated LSP because of inappropriate use of inheritance. • Thus, if you need to use functionality in another class, but you don’t want to change that functionality, consider using delegation instead of inheritance • Inheritance was simply the wrong way to gain access to the Board’s functionality • Delegation is when you hand over the responsibility for a particular task to some other class or method
  • 21. LSP – Delegation comes to rescue (Cont’d) • Board3D now maintains a list of Board objects for each legal value of “zpos” • It then delegates to the Board object to handle the requested service public Tile getTile(int x, int y, int z) { Board b = boards.get(z); return b.getTile(x,y); }
  • 22. Don’t Repeat Yourself (DRY) “Avoid duplicate code by abstracting out things that are common and putting these in a single location” DRY is about having each piece of information and behavior in your system in a single sensible place.
  • 23. DRY – Bad Example
  • 24. DRY – Correcting Bad Example 1- Let’s abstract out the common code
  • 25. DRY – Correcting Bad Example 2- Now remove the code from other locations That’s it! 
  • 26. Encapsulate What Varies • Anytime you have behavior in an application that you think is likely to change, you want to move that behavior away from parts of your application that probably won’t change very frequently. • In other words you should always try to encapsulate what varies.
  • 27. EWV- Example It helps protect your classes from unnecessary changes.
  • 28. Code To An Interface Principle “Code to an interface rather than to an implementation” • Coding to an interface, rather than to an implementation makes your software easier to extend and reuse • Objective is to hide implementation details thus reducing coupling and increasing cohesion • Any time you are writing code that interact with other classes, you have two choices. • You can write code that interact directly with sub class, Like BaseballPlayer, or you can write code that interact with Athlete. • When you run into the choice like this, you should always favor coding to the interface, not to the implementation.
  • 30. Use Inheritance Sparingly • Rule of thumb : (almost) • Inherit only when clear ‘is a’ relation exists AND • All the members in base Class will be used/implemented in sub classes • If you use inheritance other than these rules, highly probably you are mistaken
  • 31. Inappropriate use • Board3D is not a Board2D • Board3D will have useless members eventually, like tiles : int[][] • All the methods of Board2D will become useless in Board3D • Inheritance is surely not the option
  • 32. Solution • Board3D is composed of Board2D • We have “depth” times Board2Ds in our Board3D class • All the operations are delegated to Board2D methods • Board3D methods will use respective Board2D methods for “depth” times • Composition and delegation is better choice
  • 33. Summary We have covered some basic object oriented design principles that help us to write the code which is more maintainable and extensible. Following are some more principles which you can see by yourself • Dependency Injection Principle • Favor Composition Over Inheritance