SlideShare a Scribd company logo
1 of 62
Design Principles in a Nutshell
Dmytro Panin & Anton Udovychenko
12.2015
Agenda
▪ What is a good design?
▪ Complexity and simplicity
▪ KISS
▪ YAGNI
▪ Cohesiveness and coupling
▪ SOLID
▪ Q&A
Good design
▪ Design is good when a cost of changing of a design is minimum
Good design
▪ Design is good when a cost of changing of a design is minimum
▪ Easy to change
Good design
▪ Design is good when a cost of changing of a design is minimum
▪ Easy to change
Almost impossible to get it right the first time
How to make a good design?
How to make a good design?
▪ Let go of the ego
How to make a good design?
▪ Let go of the ego
▪ Be unemotional
How to make a good design?
▪ Let go of the ego
▪ Be unemotional
▪ Do code reviews
How to make a good design?
▪ Let go of the ego
▪ Be unemotional
▪ Do code reviews
▪ A good design is the one that hides inherited complexity and eliminates the
accidental complexity
How to make a good design?
▪ Let go of the ego
▪ Be unemotional
▪ Do code reviews
▪ A good design is the one that hides inherited complexity and eliminates the
accidental complexity
Software is never written, it is always rewritten. As the
software that is relevant always must be changed
Complexity
▪ Inherited from a domain
▪ Accidental complexity
KISS - Keep it simple and stupid
What is simple?
What is simple?
▪ Simple makes you concentrated
What is simple?
▪ Simple makes you concentrated
▪ Simple resolves only actual issues we know about
What is simple?
▪ Simple makes you concentrated
▪ Simple resolves only actual issues we know about
▪ Simple fails less
What is simple?
▪ Simple makes you concentrated
▪ Simple resolves only actual issues we know about
▪ Simple fails less
▪ Simple is easier to understand
Simple is not necessarily familiar.
Think YAGNI
Do we
need
it?
Day
1
We have to ask ourselves whether we need it today or not. If it's possible to
postpone something constantly for a few iterations maybe you don't need it at all.
Think YAGNI
Do we
need
it?
Day
1
Do we
actually
need
it?
Day
5
We have to ask ourselves whether we need it today or not. If it's possible to
postpone something constantly for a few iterations maybe you don't need it at all.
Think YAGNI
Do we
need
it?
Day
1
Do we
actually
need
it?
Day
5
We do
not
need it
Day
9
We have to ask ourselves whether we need it today or not. If it's possible to
postpone something constantly for a few iterations maybe you don't need it at all.
Cost of implementing
Smart Smarter
Much
smarter
Now correlation Later Result
X > Y Postpone
X == Y Postpone
X < Y ?
Do not confuse postponement and procrastination
Coupling
▪ Coupling is what you depend on...
Coupling
▪ Coupling is what you depend on...
▪ Inheritance is the worst form of coupling
Coupling
▪ Coupling is what you depend on...
▪ Inheritance is the worst form of coupling
▪ "knock out before mock out“
Coupling
▪ Coupling is what you depend on....
▪ Inheritance is the worst form of coupling
▪ "knock out before mock out“
▪ Depending on a class is a tight coupling
Coupling
▪ Coupling is what you depend on....
▪ Inheritance is the worst form of coupling
▪ "knock out before mock out“
▪ Depending on a class is a tight coupling
▪ Depending on an interface is a loose coupling
Coupling
▪ Coupling is what you depend on....
▪ Inheritance is the worst form of coupling
▪ "knock out before mock out“
A good design has high cohesion and low coupling
▪ Depending on a class is a tight coupling
▪ Depending on an interface is a loose coupling
DRY ( Do not Repeat Yourself )
▪ Every piece of knowledge in a system should have a single unambiguous
authoritative representation
▪ It reduces the cost of development
SOLID
▪ Single responsibility principle
▪ Open-Closed Principle
▪ Liskov substitution principle
▪ Interface segregation principle
▪ Dependency inversion principle
Single responsibility principle
Single responsibility principle
▪ A class should have only a single responsibility
Single responsibility principle
▪ A class should have only a single responsibility
▪ Cohesive class has single responsibility
Single responsibility principle
▪ A class should have only a single responsibility
▪ Cohesive class has single responsibility
▪ When you say "this class does this AND that" you have violated SRP
Single responsibility principle
▪ A class should have only a single responsibility
▪ Cohesive class has single responsibility
▪ When you say "this class does this AND that" you have violated SRP
▪ Long methods are bad
Commenting
Commenting
▪ Comments are usually used to cover bad code
Commenting
▪ Comments are usually used to cover bad code
▪ When code is not self-evident refactor it
Commenting
▪ Comments are usually used to cover bad code
▪ When code is not self-evident refactor it
▪ Don't comment what, instead comment why
Commenting
▪ Comments are usually used to cover bad code
▪ When code is not self-evident refactor it
▪ Don't comment what, instead comment why
▪ A good code is like a joke
Commenting
▪ Comments are usually used to cover bad code
▪ When code is not self-evident refactor it
▪ Don't comment what, instead comment why
▪ A good code is like a joke
▪ Compose method pattern
Open-Closed Principle
Open-Closed Principle
▪ Two options - to make an enhancement
1. Change existing code
2. Add a small new module of code
Open-Closed Principle
▪ Two options - to make an enhancement
1. Change existing code
2. Add a small new module of code
▪ Nobody likes existing code
Open-Closed Principle
▪ Two options - to make an enhancement
1. Change existing code
2. Add a small new module of code
▪ Nobody likes existing code
▪ Software module should be open for extension but closed from modification
Open-Closed Principle
▪ Two options - to make an enhancement
1. Change existing code
2. Add a small new module of code
▪ Nobody likes existing code
▪ Software module should be open for extension but closed from modification
▪ Rely on abstraction and polymorphism
Liskov substitution principle
Liskov substitution principle
▪ Inheritance is overused
Liskov substitution principle
▪ Inheritance is overused
▪ If an object of B should be used anywhere an object of A is used then use inheritance
Liskov substitution principle
▪ Inheritance is overused
▪ If an object of B should be used anywhere an object of A is used then use inheritance
▪ If an object of B should use an object of A, then use composition / delegation
Liskov substitution principle
▪ Inheritance is overused
▪ If an object of B should be used anywhere an object of A is used then use inheritance
▪ If an object of B should use an object of A, then use composition / delegation
▪ Inheritance demands more from a developer than composition or delegation does
Liskov substitution principle
▪ Objects in a program should be replaceable with instances of their
subtypes without altering the correctness of that program
▪ The user of a base class should be able to use an instance of a derived class
without knowing the difference
Interface segregation principle
▪ Many client-specific interfaces are better than one general-purpose interface
Alarm
Clock PCPhone TV Rooster…
Clock vs
Dependency inversion principle
▪ High-level modules should not depend on low-level modules. Both should depend
on abstractions
Dependency inversion principle
▪ High-level modules should not depend on low-level modules. Both should depend
on abstractions
▪ Abstractions should not depend upon details. Details should depend upon
abstractions
Dependency injection pattern
▪ Dependency inversion ≠ dependency injection
▪ Dependency injection pattern is an implementation of Dependency inversion
principle
Questions?
Thank you
Inspired by: Core Design Principles for Software Developers by Venkat Subramaniam

More Related Content

Viewers also liked

Viewers also liked (11)

Get along with JHipster
Get along with JHipsterGet along with JHipster
Get along with JHipster
 
Testing basics for developers
Testing basics for developersTesting basics for developers
Testing basics for developers
 
Choosing Hippo CMS
Choosing Hippo CMSChoosing Hippo CMS
Choosing Hippo CMS
 
Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)
 
SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"
SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"
SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"
 
SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"
SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"
SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"
 
SE2016 Java Dmytro Panin "JHipster: Create a Spring Boot + AngularJS project ...
SE2016 Java Dmytro Panin "JHipster: Create a Spring Boot + AngularJS project ...SE2016 Java Dmytro Panin "JHipster: Create a Spring Boot + AngularJS project ...
SE2016 Java Dmytro Panin "JHipster: Create a Spring Boot + AngularJS project ...
 
Microservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event SourcingMicroservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event Sourcing
 
Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Building and deploying microservices with event sourcing, CQRS and Docker (QC...Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Building and deploying microservices with event sourcing, CQRS and Docker (QC...
 
Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)
 
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
 

Similar to Design principles in a nutshell

Arch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best PracticesArch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best Practices
Igor Moochnick
 

Similar to Design principles in a nutshell (20)

Object Oriented Design in Ruby
Object Oriented Design in RubyObject Oriented Design in Ruby
Object Oriented Design in Ruby
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Learning Before, During and After
Learning Before, During and AfterLearning Before, During and After
Learning Before, During and After
 
Going Evergreen, RubyConf 2014
Going Evergreen, RubyConf 2014Going Evergreen, RubyConf 2014
Going Evergreen, RubyConf 2014
 
Seven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC OsloSeven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC Oslo
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
Software Developer Career Unplugged - GeeCon 2013
Software Developer Career Unplugged - GeeCon 2013Software Developer Career Unplugged - GeeCon 2013
Software Developer Career Unplugged - GeeCon 2013
 
How To Handle Your Tech Debt Better - Sean Moir
How To Handle Your Tech Debt Better - Sean MoirHow To Handle Your Tech Debt Better - Sean Moir
How To Handle Your Tech Debt Better - Sean Moir
 
Becoming a better developer by using the SOLID design principles
Becoming a better developer by using the SOLID design principlesBecoming a better developer by using the SOLID design principles
Becoming a better developer by using the SOLID design principles
 
Christian Heilmann - Seven Things to Do to Make You a Happier JavaScript Deve...
Christian Heilmann - Seven Things to Do to Make You a Happier JavaScript Deve...Christian Heilmann - Seven Things to Do to Make You a Happier JavaScript Deve...
Christian Heilmann - Seven Things to Do to Make You a Happier JavaScript Deve...
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
 
Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Clean code: SOLID (iOS)
Clean code: SOLID (iOS)
 
Design Principles
Design PrinciplesDesign Principles
Design Principles
 
Arch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best PracticesArch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best Practices
 
5 unspoke rules of contributing to open source software
5 unspoke rules of contributing to open source software5 unspoke rules of contributing to open source software
5 unspoke rules of contributing to open source software
 
Usability Testing: Targeting Mobile Devices
Usability Testing: Targeting Mobile DevicesUsability Testing: Targeting Mobile Devices
Usability Testing: Targeting Mobile Devices
 
10 mistakes when you move to topic-based authoring
10 mistakes when you move to topic-based authoring10 mistakes when you move to topic-based authoring
10 mistakes when you move to topic-based authoring
 
Solid
SolidSolid
Solid
 
Understanding bdd and tdd with lego
Understanding bdd and tdd with legoUnderstanding bdd and tdd with lego
Understanding bdd and tdd with lego
 

Recently uploaded

Recently uploaded (20)

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
 
WSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital Businesses
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 

Design principles in a nutshell

  • 1. Design Principles in a Nutshell Dmytro Panin & Anton Udovychenko 12.2015
  • 2. Agenda ▪ What is a good design? ▪ Complexity and simplicity ▪ KISS ▪ YAGNI ▪ Cohesiveness and coupling ▪ SOLID ▪ Q&A
  • 3. Good design ▪ Design is good when a cost of changing of a design is minimum
  • 4. Good design ▪ Design is good when a cost of changing of a design is minimum ▪ Easy to change
  • 5. Good design ▪ Design is good when a cost of changing of a design is minimum ▪ Easy to change Almost impossible to get it right the first time
  • 6. How to make a good design?
  • 7. How to make a good design? ▪ Let go of the ego
  • 8. How to make a good design? ▪ Let go of the ego ▪ Be unemotional
  • 9. How to make a good design? ▪ Let go of the ego ▪ Be unemotional ▪ Do code reviews
  • 10. How to make a good design? ▪ Let go of the ego ▪ Be unemotional ▪ Do code reviews ▪ A good design is the one that hides inherited complexity and eliminates the accidental complexity
  • 11. How to make a good design? ▪ Let go of the ego ▪ Be unemotional ▪ Do code reviews ▪ A good design is the one that hides inherited complexity and eliminates the accidental complexity Software is never written, it is always rewritten. As the software that is relevant always must be changed
  • 12. Complexity ▪ Inherited from a domain ▪ Accidental complexity
  • 13. KISS - Keep it simple and stupid
  • 15. What is simple? ▪ Simple makes you concentrated
  • 16. What is simple? ▪ Simple makes you concentrated ▪ Simple resolves only actual issues we know about
  • 17. What is simple? ▪ Simple makes you concentrated ▪ Simple resolves only actual issues we know about ▪ Simple fails less
  • 18. What is simple? ▪ Simple makes you concentrated ▪ Simple resolves only actual issues we know about ▪ Simple fails less ▪ Simple is easier to understand
  • 19. Simple is not necessarily familiar.
  • 20. Think YAGNI Do we need it? Day 1 We have to ask ourselves whether we need it today or not. If it's possible to postpone something constantly for a few iterations maybe you don't need it at all.
  • 21. Think YAGNI Do we need it? Day 1 Do we actually need it? Day 5 We have to ask ourselves whether we need it today or not. If it's possible to postpone something constantly for a few iterations maybe you don't need it at all.
  • 22. Think YAGNI Do we need it? Day 1 Do we actually need it? Day 5 We do not need it Day 9 We have to ask ourselves whether we need it today or not. If it's possible to postpone something constantly for a few iterations maybe you don't need it at all.
  • 23. Cost of implementing Smart Smarter Much smarter Now correlation Later Result X > Y Postpone X == Y Postpone X < Y ?
  • 24. Do not confuse postponement and procrastination
  • 25. Coupling ▪ Coupling is what you depend on...
  • 26. Coupling ▪ Coupling is what you depend on... ▪ Inheritance is the worst form of coupling
  • 27. Coupling ▪ Coupling is what you depend on... ▪ Inheritance is the worst form of coupling ▪ "knock out before mock out“
  • 28. Coupling ▪ Coupling is what you depend on.... ▪ Inheritance is the worst form of coupling ▪ "knock out before mock out“ ▪ Depending on a class is a tight coupling
  • 29. Coupling ▪ Coupling is what you depend on.... ▪ Inheritance is the worst form of coupling ▪ "knock out before mock out“ ▪ Depending on a class is a tight coupling ▪ Depending on an interface is a loose coupling
  • 30. Coupling ▪ Coupling is what you depend on.... ▪ Inheritance is the worst form of coupling ▪ "knock out before mock out“ A good design has high cohesion and low coupling ▪ Depending on a class is a tight coupling ▪ Depending on an interface is a loose coupling
  • 31. DRY ( Do not Repeat Yourself ) ▪ Every piece of knowledge in a system should have a single unambiguous authoritative representation ▪ It reduces the cost of development
  • 32. SOLID ▪ Single responsibility principle ▪ Open-Closed Principle ▪ Liskov substitution principle ▪ Interface segregation principle ▪ Dependency inversion principle
  • 34. Single responsibility principle ▪ A class should have only a single responsibility
  • 35. Single responsibility principle ▪ A class should have only a single responsibility ▪ Cohesive class has single responsibility
  • 36. Single responsibility principle ▪ A class should have only a single responsibility ▪ Cohesive class has single responsibility ▪ When you say "this class does this AND that" you have violated SRP
  • 37. Single responsibility principle ▪ A class should have only a single responsibility ▪ Cohesive class has single responsibility ▪ When you say "this class does this AND that" you have violated SRP ▪ Long methods are bad
  • 39. Commenting ▪ Comments are usually used to cover bad code
  • 40. Commenting ▪ Comments are usually used to cover bad code ▪ When code is not self-evident refactor it
  • 41. Commenting ▪ Comments are usually used to cover bad code ▪ When code is not self-evident refactor it ▪ Don't comment what, instead comment why
  • 42. Commenting ▪ Comments are usually used to cover bad code ▪ When code is not self-evident refactor it ▪ Don't comment what, instead comment why ▪ A good code is like a joke
  • 43. Commenting ▪ Comments are usually used to cover bad code ▪ When code is not self-evident refactor it ▪ Don't comment what, instead comment why ▪ A good code is like a joke ▪ Compose method pattern
  • 45. Open-Closed Principle ▪ Two options - to make an enhancement 1. Change existing code 2. Add a small new module of code
  • 46. Open-Closed Principle ▪ Two options - to make an enhancement 1. Change existing code 2. Add a small new module of code ▪ Nobody likes existing code
  • 47. Open-Closed Principle ▪ Two options - to make an enhancement 1. Change existing code 2. Add a small new module of code ▪ Nobody likes existing code ▪ Software module should be open for extension but closed from modification
  • 48. Open-Closed Principle ▪ Two options - to make an enhancement 1. Change existing code 2. Add a small new module of code ▪ Nobody likes existing code ▪ Software module should be open for extension but closed from modification ▪ Rely on abstraction and polymorphism
  • 49.
  • 51. Liskov substitution principle ▪ Inheritance is overused
  • 52. Liskov substitution principle ▪ Inheritance is overused ▪ If an object of B should be used anywhere an object of A is used then use inheritance
  • 53. Liskov substitution principle ▪ Inheritance is overused ▪ If an object of B should be used anywhere an object of A is used then use inheritance ▪ If an object of B should use an object of A, then use composition / delegation
  • 54. Liskov substitution principle ▪ Inheritance is overused ▪ If an object of B should be used anywhere an object of A is used then use inheritance ▪ If an object of B should use an object of A, then use composition / delegation ▪ Inheritance demands more from a developer than composition or delegation does
  • 55. Liskov substitution principle ▪ Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program ▪ The user of a base class should be able to use an instance of a derived class without knowing the difference
  • 56.
  • 57. Interface segregation principle ▪ Many client-specific interfaces are better than one general-purpose interface Alarm Clock PCPhone TV Rooster… Clock vs
  • 58. Dependency inversion principle ▪ High-level modules should not depend on low-level modules. Both should depend on abstractions
  • 59. Dependency inversion principle ▪ High-level modules should not depend on low-level modules. Both should depend on abstractions ▪ Abstractions should not depend upon details. Details should depend upon abstractions
  • 60.
  • 61. Dependency injection pattern ▪ Dependency inversion ≠ dependency injection ▪ Dependency injection pattern is an implementation of Dependency inversion principle
  • 62. Questions? Thank you Inspired by: Core Design Principles for Software Developers by Venkat Subramaniam

Editor's Notes

  1. *Single responsibility principle* Cohesive class has single responsibility When you say "this class does this AND that" you have violated SRP Long methods are bad *Open-Closed Principle* Two options - to make an enhancement 1. change existing code 2. add a small new module of code nobody like existing code Software module should be open for extension but closed from modification Rely on abstraction and polymorhism *Liskov substitution principle* Inheretence is overused If an object of B should be used anywhere an object of A is used then use inheritance If an object of B should use an object of A, then use composition / delegation Inheritance demands more from a developer than composition or delegation does. “objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.” The user of a base class should be able to use an instance of a derived class without knowing the difference. *Interface segregation principle* many client-specific interfaces are better than one general-purpose interface Clock example Alarm ^ | __________________________________________________________ | | | ....... | TV Clock SPhone Wife *Dependency injection principle* A class should not depende on another class, they both have to depend on an abstraction (interface)
  2. i.e. only one potential change in the software's specification should be able to affect the specification of the class
  3. i.e. only one potential change in the software's specification should be able to affect the specification of the class
  4. i.e. only one potential change in the software's specification should be able to affect the specification of the class
  5. i.e. only one potential change in the software's specification should be able to affect the specification of the class
  6. i.e. only one potential change in the software's specification should be able to affect the specification of the class