SlideShare a Scribd company logo
1 of 35
Download to read offline
>< nextprevious
Object Oriented Design Principles
How to become a SOLID programmer
Tran Duc Thang
Framgia Vietnam - Business Strategy Office - Human Development Section
A guide to make a well-designed application with Laravel
1
>< nextprevious
“Proper Object Oriented design makes
a developer's life easy, whereas bad
design makes it a disaster.”
2
Table of Contents
01
Design Principles first look
‣ What is Design Principle?
‣ Design Principle vs Design Pattern
02
03
04
>< nextprevious
SOLID in depth
‣ What are SOLID?
‣ Decoding SOLID
‣ Other related principles
Building well-design app
‣ A story with MVC
‣ Some ideas when working with Laravel
‣ Symptoms of Bad Design
Summarisation
‣ Annotations, disclaims and notes
3
>< nextprevious
Design Principles
• Object Oriented Design Patterns
‣ A general repeatable solution to a commonly
occurring problem in software design.
‣ A description or template for how to solve a
problem that can be used in many different
situations.
‣ Gained popularity after the book “Design
Patterns: Elements of Reusable Object-
Oriented Software” was published in 1994
by the so-called “Gang of Four”
4
>< nextprevious
Design Principles
• Object Oriented Design Principles
‣ Associated to Robert Cecil Martin who
gathered them in “Agile Software
Development: Principles, Patterns, and
Practices”
‣ Represent a set of guidelines that ensures
OOP concepts, then helps us to avoid having
a bad design.
‣ It’s abstract. (Not concrete).
5
>< nextprevious
Design Principles
• Robert Cecil Martin
‣ Agile software development:
principles, patterns, and
practices.
‣ Clean code: a handbook of
agile software craftsmanship.
‣ The clean coder: a code of
conduct for professional
programmers.
6
>< nextprevious
Design Principles
• Some Software Design Principles in examples
‣ DRY (Don’t Repeat Yourself)
‣ KISS (Keep It Simple, Stupid!)
‣ YAGNI (You Aren't Gonna Need It)
7
>< nextprevious
Design Principles
• Design Patterns vs Design Principles
‣ Principles: low-level, general guidelines
‣ Patterns: high-level, concrete examples.
Provide reusable solutions to real world
problems.
‣ Good Design Patterns should comply good
Design Principles
8
>< nextprevious
SOLID in depth
• What are SOLID?
‣ A mnemonic acronym introduced by Michael
Feathers for the “first five principles”
named by Robert Cecil Martin.
‣ Single responsibility principle
‣ Open/closed principle
‣ Liskov substitution principle
‣ Interface segregation principle
‣ Dependency inversion principle
9
>< nextprevious
SOLID in depth
• Single responsibility principle (SRP)
‣ A class should have only a single
responsibility. In other words, a class should
have one, and only one, reason to change.
10
>< nextprevious
SOLID in depth
11
>< nextprevious
SOLID in depth
• Open/closed principle (OCP)
‣ Software entities (classes, modules,
functions, etc.) should be open for
extension, but closed for modification
‣ An entity can allow its behaviour to be
extended without modifying its source code
12
>< nextprevious
SOLID in depth
13
>< nextprevious
SOLID in depth
• Liskov substitution principle (LSP)
‣ If S is a subtype of T, then objects of type T
may be replaced with objects of type S
without altering any of the desirable
properties of that program.
14
>< nextprevious
SOLID in depth
15
>< nextprevious
SOLID in depth
• Interface segregation principle (ISP)
‣ No client should be forced to depend on
methods it does not use.
‣ Many client-specific interfaces are better than
one general-purpose interface.
16
>< nextprevious
SOLID in depth
17
>< nextprevious
SOLID in depth
• Dependency inversion principle (ISP)
‣ High-level modules should not depend on
low-level modules. Both should depend on
abstractions.
‣ Abstractions should not depend on details.
Details should depend on abstractions.
18
>< nextprevious
SOLID in depth
19
>< nextprevious
SOLID in depth
Some other concepts related to SOLID
• Separation of Concerns (SoC)
‣ The process of breaking a computer program
into distinct features that overlap in
functionality as little as possible
20
>< nextprevious
SOLID in depth
• Law of Demeter (LoD) aka Principle of Least
Knowledge
‣ Each unit should have only limited knowledge
about other units: only units "closely" related
to the current unit.
‣ Each unit should only talk to its friends; don't
talk to strangers.
‣ Only talk to your immediate friends.
21
>< nextprevious
SOLID in depth
• Program to an interface, not an implementation
‣ One of good object-oriented design
techniques that GoF mentioned in “Design
Patterns: Elements of Reusable Object-
Oriented Software”
22
>< nextprevious
SOLID in depth
• SOLID in Action - Checkout examples at Github
https://github.com/wataridori/solid-php-example
23
>< nextprevious
SOLID in depth
All SOLID principles work perfectly together.
Breaking one principle may also make some (or even
all) of the remaining principles become broken too!
24
>< nextprevious
Building well-designed app
• The MVC Story: Model vs Controller
‣ Where to put your business logic?
‣ Fat Controllers - Skinny Models?
‣ Fat Models - Skinny Controllers?
‣ Fat Models - Fat Controllers?
25
>< nextprevious
“MVC is killing you”
~ Taylor Otwell - Laravel’s creator ~
26
>< nextprevious
Think different!
“Think outside of the ‘Model’ Box”
27
>< nextprevious
• Some ideas when working with Laravel
‣ Get rid of “Model” with lots of business, try “Entity”
‣ Repository design pattern for Data Access Layer
‣ Form Request Validation
‣ Job
‣ Event
‣ View Presenter, or any kind of wrappers that helps you get rid of
God Object
‣ Design Patterns
‣ …
Building well-designed app
28
>< nextprevious
• Symptoms of Bad Design
‣ Rigidity
‣ Fragility
‣ Immobility
‣ Viscosity
‣ Needless Complexity
‣ Needless Repetition
‣ Opacity
Building well-designed app
29
>< nextprevious
• Funny: Avoid STUPID codes
‣ Singleton Pattern
‣ Tight coupling
‣ Untestability
‣ Premature Optimization
‣ Indescriptive Naming
‣ Duplication
Building well-designed app
30
>< nextprevious
Summarisation
• SOLID principles, as well as other design
principles and design patterns help you to build
large applications which are easy-to-be-
extended, easy-to-be-maintained, easy-to-be-
tested.
31
>< nextprevious
Summarisation
• SOLID principles, as well as other design
principles and design patterns help you to build
LARGE applications which are easy-to-be-
extended, easy-to-be-maintained, easy-to-be-
tested.
• Principles are just a set of GUIDELINES. They
are not LAWS!
• Don’t take the above argument as a reason to
be lazy!
32
>< nextprevious
Summarisation
Extract Responsibilities
&&
Programming to the Interface
33
>< nextprevious
References
‣ https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
‣ http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
‣ http://www.oodesign.com/
‣ https://lostechies.com/derickbailey/2009/02/11/solid-
development-principles-in-motivational-pictures/
‣ https://nikic.github.io/2011/12/27/Dont-be-STUPID-GRASP-
SOLID.html
‣ http://williamdurand.fr/2013/07/30/from-stupid-to-solid-code/
‣ http://www.codeproject.com/Articles/567768/Object-Oriented-
Design-Principles
‣ “Design Principles and Design Patterns” - Robert C. Martin
‣ “From Apprentice To Artisan” - Taylor Otwell
34
>< nextprevious
Thank you for listening!
Q&A
For any discussion, you can refer this post on Viblo
https://viblo.asia/thangtd90/posts/pVYRPJPmG4ng
35

More Related Content

What's hot

7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable codeGeshan Manandhar
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaEdureka!
 
Creational pattern
Creational patternCreational pattern
Creational patternHimanshu
 
Solid design principles
Solid design principlesSolid design principles
Solid design principlesMahmoud Asadi
 
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...Simplilearn
 
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | EdurekaDocker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | EdurekaEdureka!
 
Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean ArchitectureRoc Boronat
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best PracticesTheo Jungeblut
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan GoleChetan Gole
 
Running Spring Boot Applications as GraalVM Native Images
Running Spring Boot Applications as GraalVM Native ImagesRunning Spring Boot Applications as GraalVM Native Images
Running Spring Boot Applications as GraalVM Native ImagesVMware Tanzu
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSergey Karpushin
 
Open Closed Principle kata
Open Closed Principle kataOpen Closed Principle kata
Open Closed Principle kataPaul Blundell
 

What's hot (20)

7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Agile sdlc
Agile sdlcAgile sdlc
Agile sdlc
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Dockerfile
Dockerfile Dockerfile
Dockerfile
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Clean code
Clean code Clean code
Clean code
 
Solid design principles
Solid design principlesSolid design principles
Solid design principles
 
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | EdurekaDocker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
 
Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean Architecture
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Running Spring Boot Applications as GraalVM Native Images
Running Spring Boot Applications as GraalVM Native ImagesRunning Spring Boot Applications as GraalVM Native Images
Running Spring Boot Applications as GraalVM Native Images
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
 
Open Closed Principle kata
Open Closed Principle kataOpen Closed Principle kata
Open Closed Principle kata
 

Similar to Object Oriented Design Principles

Solid principles of oo design
Solid principles of oo designSolid principles of oo design
Solid principles of oo designConfiz
 
Software design principles
Software design principlesSoftware design principles
Software design principlesMd.Mojibul Hoque
 
bGenius kennissessie_20120510
bGenius kennissessie_20120510bGenius kennissessie_20120510
bGenius kennissessie_20120510bgenius
 
Developing solid applications
Developing solid applicationsDeveloping solid applications
Developing solid applicationsNilesh Bangar
 
Fifteen Years of DevOps -- LISA 2012 keynote
Fifteen Years of DevOps -- LISA 2012 keynoteFifteen Years of DevOps -- LISA 2012 keynote
Fifteen Years of DevOps -- LISA 2012 keynoteGeoff Halprin
 
Software design - Write solid software with the ideal chalk
Software design - Write solid software with the  ideal chalkSoftware design - Write solid software with the  ideal chalk
Software design - Write solid software with the ideal chalkAlejandro Claro Mosqueda
 
Are You a SOLID Coder?
Are You a SOLID Coder?Are You a SOLID Coder?
Are You a SOLID Coder?Steve Green
 
Create first android app with MVVM Architecture
Create first android app with MVVM ArchitectureCreate first android app with MVVM Architecture
Create first android app with MVVM Architecturekhushbu thakker
 
SOLID principles-Present
SOLID principles-PresentSOLID principles-Present
SOLID principles-PresentQuang Nguyen
 
Use Design Principle to Improve code quality
Use Design Principle to Improve code qualityUse Design Principle to Improve code quality
Use Design Principle to Improve code qualityHebin Wei
 
The OO Design Principles
The OO Design PrinciplesThe OO Design Principles
The OO Design PrinciplesSteve Zhang
 
Solid OO & Clean Coding is essential to successful Agile development
Solid OO & Clean Coding is essential to successful Agile developmentSolid OO & Clean Coding is essential to successful Agile development
Solid OO & Clean Coding is essential to successful Agile developmentSimon Gould
 
Fed Up Of Framework Hype Dcphp
Fed Up Of Framework Hype DcphpFed Up Of Framework Hype Dcphp
Fed Up Of Framework Hype DcphpTony Bibbs
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedAlexander Makarov
 
ICONUK 2014 - From Idea To App
ICONUK 2014 - From Idea To AppICONUK 2014 - From Idea To App
ICONUK 2014 - From Idea To AppRené Winkelmeyer
 
Architecting Solutions and Systems – Randy’s Secrets to Success
Architecting Solutions and Systems – Randy’s Secrets to SuccessArchitecting Solutions and Systems – Randy’s Secrets to Success
Architecting Solutions and Systems – Randy’s Secrets to SuccessRandy Williams
 
A modern architecturereview–usingcodereviewtools-ver-3.5
A modern architecturereview–usingcodereviewtools-ver-3.5A modern architecturereview–usingcodereviewtools-ver-3.5
A modern architecturereview–usingcodereviewtools-ver-3.5SSW
 
Refactoring to SOLID Code
Refactoring to SOLID CodeRefactoring to SOLID Code
Refactoring to SOLID CodeAdil Mughal
 

Similar to Object Oriented Design Principles (20)

Solid principles of oo design
Solid principles of oo designSolid principles of oo design
Solid principles of oo design
 
Software design principles
Software design principlesSoftware design principles
Software design principles
 
bGenius kennissessie_20120510
bGenius kennissessie_20120510bGenius kennissessie_20120510
bGenius kennissessie_20120510
 
Developing solid applications
Developing solid applicationsDeveloping solid applications
Developing solid applications
 
Fifteen Years of DevOps -- LISA 2012 keynote
Fifteen Years of DevOps -- LISA 2012 keynoteFifteen Years of DevOps -- LISA 2012 keynote
Fifteen Years of DevOps -- LISA 2012 keynote
 
Software design - Write solid software with the ideal chalk
Software design - Write solid software with the  ideal chalkSoftware design - Write solid software with the  ideal chalk
Software design - Write solid software with the ideal chalk
 
Are You a SOLID Coder?
Are You a SOLID Coder?Are You a SOLID Coder?
Are You a SOLID Coder?
 
Create first android app with MVVM Architecture
Create first android app with MVVM ArchitectureCreate first android app with MVVM Architecture
Create first android app with MVVM Architecture
 
SOLID principles-Present
SOLID principles-PresentSOLID principles-Present
SOLID principles-Present
 
Use Design Principle to Improve code quality
Use Design Principle to Improve code qualityUse Design Principle to Improve code quality
Use Design Principle to Improve code quality
 
The OO Design Principles
The OO Design PrinciplesThe OO Design Principles
The OO Design Principles
 
Solid OO & Clean Coding is essential to successful Agile development
Solid OO & Clean Coding is essential to successful Agile developmentSolid OO & Clean Coding is essential to successful Agile development
Solid OO & Clean Coding is essential to successful Agile development
 
Fed Up Of Framework Hype Dcphp
Fed Up Of Framework Hype DcphpFed Up Of Framework Hype Dcphp
Fed Up Of Framework Hype Dcphp
 
Icebreaker with DevOps
Icebreaker with DevOpsIcebreaker with DevOps
Icebreaker with DevOps
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developed
 
ICONUK 2014 - From Idea To App
ICONUK 2014 - From Idea To AppICONUK 2014 - From Idea To App
ICONUK 2014 - From Idea To App
 
Architecting Solutions and Systems – Randy’s Secrets to Success
Architecting Solutions and Systems – Randy’s Secrets to SuccessArchitecting Solutions and Systems – Randy’s Secrets to Success
Architecting Solutions and Systems – Randy’s Secrets to Success
 
A modern architecturereview–usingcodereviewtools-ver-3.5
A modern architecturereview–usingcodereviewtools-ver-3.5A modern architecturereview–usingcodereviewtools-ver-3.5
A modern architecturereview–usingcodereviewtools-ver-3.5
 
Refactoring to SOLID Code
Refactoring to SOLID CodeRefactoring to SOLID Code
Refactoring to SOLID Code
 
L21 Architecture and Agile
L21 Architecture and AgileL21 Architecture and Agile
L21 Architecture and Agile
 

Recently uploaded

Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 

Recently uploaded (20)

Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 

Object Oriented Design Principles

  • 1. >< nextprevious Object Oriented Design Principles How to become a SOLID programmer Tran Duc Thang Framgia Vietnam - Business Strategy Office - Human Development Section A guide to make a well-designed application with Laravel 1
  • 2. >< nextprevious “Proper Object Oriented design makes a developer's life easy, whereas bad design makes it a disaster.” 2
  • 3. Table of Contents 01 Design Principles first look ‣ What is Design Principle? ‣ Design Principle vs Design Pattern 02 03 04 >< nextprevious SOLID in depth ‣ What are SOLID? ‣ Decoding SOLID ‣ Other related principles Building well-design app ‣ A story with MVC ‣ Some ideas when working with Laravel ‣ Symptoms of Bad Design Summarisation ‣ Annotations, disclaims and notes 3
  • 4. >< nextprevious Design Principles • Object Oriented Design Patterns ‣ A general repeatable solution to a commonly occurring problem in software design. ‣ A description or template for how to solve a problem that can be used in many different situations. ‣ Gained popularity after the book “Design Patterns: Elements of Reusable Object- Oriented Software” was published in 1994 by the so-called “Gang of Four” 4
  • 5. >< nextprevious Design Principles • Object Oriented Design Principles ‣ Associated to Robert Cecil Martin who gathered them in “Agile Software Development: Principles, Patterns, and Practices” ‣ Represent a set of guidelines that ensures OOP concepts, then helps us to avoid having a bad design. ‣ It’s abstract. (Not concrete). 5
  • 6. >< nextprevious Design Principles • Robert Cecil Martin ‣ Agile software development: principles, patterns, and practices. ‣ Clean code: a handbook of agile software craftsmanship. ‣ The clean coder: a code of conduct for professional programmers. 6
  • 7. >< nextprevious Design Principles • Some Software Design Principles in examples ‣ DRY (Don’t Repeat Yourself) ‣ KISS (Keep It Simple, Stupid!) ‣ YAGNI (You Aren't Gonna Need It) 7
  • 8. >< nextprevious Design Principles • Design Patterns vs Design Principles ‣ Principles: low-level, general guidelines ‣ Patterns: high-level, concrete examples. Provide reusable solutions to real world problems. ‣ Good Design Patterns should comply good Design Principles 8
  • 9. >< nextprevious SOLID in depth • What are SOLID? ‣ A mnemonic acronym introduced by Michael Feathers for the “first five principles” named by Robert Cecil Martin. ‣ Single responsibility principle ‣ Open/closed principle ‣ Liskov substitution principle ‣ Interface segregation principle ‣ Dependency inversion principle 9
  • 10. >< nextprevious SOLID in depth • Single responsibility principle (SRP) ‣ A class should have only a single responsibility. In other words, a class should have one, and only one, reason to change. 10
  • 12. >< nextprevious SOLID in depth • Open/closed principle (OCP) ‣ Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification ‣ An entity can allow its behaviour to be extended without modifying its source code 12
  • 14. >< nextprevious SOLID in depth • Liskov substitution principle (LSP) ‣ If S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of that program. 14
  • 16. >< nextprevious SOLID in depth • Interface segregation principle (ISP) ‣ No client should be forced to depend on methods it does not use. ‣ Many client-specific interfaces are better than one general-purpose interface. 16
  • 18. >< nextprevious SOLID in depth • Dependency inversion principle (ISP) ‣ High-level modules should not depend on low-level modules. Both should depend on abstractions. ‣ Abstractions should not depend on details. Details should depend on abstractions. 18
  • 20. >< nextprevious SOLID in depth Some other concepts related to SOLID • Separation of Concerns (SoC) ‣ The process of breaking a computer program into distinct features that overlap in functionality as little as possible 20
  • 21. >< nextprevious SOLID in depth • Law of Demeter (LoD) aka Principle of Least Knowledge ‣ Each unit should have only limited knowledge about other units: only units "closely" related to the current unit. ‣ Each unit should only talk to its friends; don't talk to strangers. ‣ Only talk to your immediate friends. 21
  • 22. >< nextprevious SOLID in depth • Program to an interface, not an implementation ‣ One of good object-oriented design techniques that GoF mentioned in “Design Patterns: Elements of Reusable Object- Oriented Software” 22
  • 23. >< nextprevious SOLID in depth • SOLID in Action - Checkout examples at Github https://github.com/wataridori/solid-php-example 23
  • 24. >< nextprevious SOLID in depth All SOLID principles work perfectly together. Breaking one principle may also make some (or even all) of the remaining principles become broken too! 24
  • 25. >< nextprevious Building well-designed app • The MVC Story: Model vs Controller ‣ Where to put your business logic? ‣ Fat Controllers - Skinny Models? ‣ Fat Models - Skinny Controllers? ‣ Fat Models - Fat Controllers? 25
  • 26. >< nextprevious “MVC is killing you” ~ Taylor Otwell - Laravel’s creator ~ 26
  • 27. >< nextprevious Think different! “Think outside of the ‘Model’ Box” 27
  • 28. >< nextprevious • Some ideas when working with Laravel ‣ Get rid of “Model” with lots of business, try “Entity” ‣ Repository design pattern for Data Access Layer ‣ Form Request Validation ‣ Job ‣ Event ‣ View Presenter, or any kind of wrappers that helps you get rid of God Object ‣ Design Patterns ‣ … Building well-designed app 28
  • 29. >< nextprevious • Symptoms of Bad Design ‣ Rigidity ‣ Fragility ‣ Immobility ‣ Viscosity ‣ Needless Complexity ‣ Needless Repetition ‣ Opacity Building well-designed app 29
  • 30. >< nextprevious • Funny: Avoid STUPID codes ‣ Singleton Pattern ‣ Tight coupling ‣ Untestability ‣ Premature Optimization ‣ Indescriptive Naming ‣ Duplication Building well-designed app 30
  • 31. >< nextprevious Summarisation • SOLID principles, as well as other design principles and design patterns help you to build large applications which are easy-to-be- extended, easy-to-be-maintained, easy-to-be- tested. 31
  • 32. >< nextprevious Summarisation • SOLID principles, as well as other design principles and design patterns help you to build LARGE applications which are easy-to-be- extended, easy-to-be-maintained, easy-to-be- tested. • Principles are just a set of GUIDELINES. They are not LAWS! • Don’t take the above argument as a reason to be lazy! 32
  • 34. >< nextprevious References ‣ https://en.wikipedia.org/wiki/SOLID_(object-oriented_design) ‣ http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod ‣ http://www.oodesign.com/ ‣ https://lostechies.com/derickbailey/2009/02/11/solid- development-principles-in-motivational-pictures/ ‣ https://nikic.github.io/2011/12/27/Dont-be-STUPID-GRASP- SOLID.html ‣ http://williamdurand.fr/2013/07/30/from-stupid-to-solid-code/ ‣ http://www.codeproject.com/Articles/567768/Object-Oriented- Design-Principles ‣ “Design Principles and Design Patterns” - Robert C. Martin ‣ “From Apprentice To Artisan” - Taylor Otwell 34
  • 35. >< nextprevious Thank you for listening! Q&A For any discussion, you can refer this post on Viblo https://viblo.asia/thangtd90/posts/pVYRPJPmG4ng 35