SlideShare a Scribd company logo
1 of 42
Download to read offline
Emerging .NET Devs
October User Group Meeting




Design Principles &
Practices


Adil Ahmed Mughal
Zubair Ahmed
Refactoring to SOLID Code

      Emerging .NET Devs
Session => Refactoring to SOLID Code
What You must already know:

- Object Oriented Programming Language such as Java, C++, C#
- Professional Experience

What You will learn today:

- Good Practices
- OO Principles

Sponsors:
Speaker => Adil Ahmed Mughal
Affiliations:




Contact Information:
     adil.mughal@live.com

     @adilamughal

     http://www.adilmughal.com
Agenda
         This is not a single side talk, its discussion!
  Promise me that you will raise hand when you have query?

• How You Code Today?

• What is Bad Design?

• What would You Call a Good Design?

• SOLID Principles!
How You Code Today?
• Do you care about design principles or patterns?
• Anti-patterns?
• Is your code Agile?
• Do you Refactor your code?
• Is your code design bad or good?
Bad design is...
                         Needless
  Rigid
                        Complexity

                         Needless
 Fragile
                        Repetition

Immobile


Viscous
What would You Call a Good Design?

• Reliability

• Flexibility

• Separations of Concerns

• Reusability

• Maintainability
SOLID

    Object Oriented Principles
Introduced by Robert C. Martin in
           early 2000s
SOLID Principles
• S – Single Responsibility Principle (SRP)

• O – Open Closed Principle (OCP)

• L – Liskov Substitution Principle (LSP)

• I – Interface Segregation Principle (ISP)

• D – Dependency Inversion Principle (DIP)
Single Responsibility Principle
            (SRP)
The Single Responsibility Principle


"A responsibility is a reason to change, a class or
module should have one, and only one, reason
to change."
The Single Responsibility Principle
• “There should never be more than one reason for a
  class to change.”

• More responsibilities => More likelihood of change

• Dijkstra’s SoC: separation of concerns

• Applies on every level of code

• Solves the naming dilemma
Trade Validator

         Trade
        Validator
                                       DB

Trade

        What is wrong here: Changes if DB
        changes or Business Logic Changes
Refactored Trade Validator

           Trade                                         Trade
          Validator                                     Source

Trade
                                                             DB


             What's its job?
             Classes must have an identifiable single
             responsibility.
The Open-Closed Principle (OCP)
The Open Closed Principle


“Software Entities (Classes, Modules, Functions,
etc.) should be open for extension, but closed for
modification”
The Open Closed Principle
• Modules that conform to the open-closed principle have
  two primary attributes
   – Open For Extension
      • behavior of the module can be extended

   – Closed for Modification
      • The source code of such a module is inviolate


• The normal way to extend the behavior of a module is to
  make changes to that module. How can these two opposing
  attributes be resolved?
OCP – Change behavior without
           changing code?
• Abstraction is the key to achieve it




      Client                         Server


                     Closed Client
OCP – Change behavior without
       changing code?


Client                   Abstract
                          Server

                          Server

           Open Client
Liskov Substitution Principle
           (LSP)
Liskov Substitution Principle


“Functions that reference a base class must be
able to use objects of derived classes without
knowing it."
Interface Segregation Principle
             (ISP)
Interface Segregation Principle

“Clients should not be forced to depend upon
interfaces that they do not use.”

• Prefer small, cohesive interfaces to fat
interfaces
Dependency Inversion Principle
           (DIP)
Dependency Inversion Principle

“High level modules should not depend upon low
level modules. Both should depend upon
abstractions. “

“Abstractions should not depend upon details.
Details should depend upon abstractions.”
Trade Validator
                                              Introduce stability
High Level (Less Stable)                       with abstraction
           Trade                              Trade
          Validator                          Source


  Trade
        Low Level                                      DB
      (More Stable)
Better Trade Validator


Trade Validator
                            <Interface>
                           ITradeSource


Trade                     DbTradeSource


                                   DB
Extensible Trade Validator
                                 <Interface>
TradeValidator                   ITradeSource



Trade            DbTradeSource       WSTradeSource




                   DB
                                      Cloud
DEMO

Let’s Refactor!
Actions => From Now On
               Learn, Practice and Make it your Habit

Links:
- ObjectMentor.com
- Practices and Patterns on MSDN


Books:
References
• Combatting Software Entropy using Design Principles
  and Practices – Hammad Rajjoub – TechEd ME

• Agile Principles, Patterns and Practices using C# by
  Robert.C.Martin

• Special thanks for motivational poster images by
  NimblePros
Thank You!

Refactoring to SOLID Code
     Emerging .NET Devs

More Related Content

What's hot

Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
Sergey Karpushin
 
Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software Craftsmanship
Theo Jungeblut
 
Implementing The Open/Closed Principle
Implementing The Open/Closed PrincipleImplementing The Open/Closed Principle
Implementing The Open/Closed Principle
Sam Hennessy
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
Theo Jungeblut
 

What's hot (20)

Add Some DDD to Your ASP.NET MVC, OK?
Add Some DDD to Your ASP.NET MVC, OK?Add Some DDD to Your ASP.NET MVC, OK?
Add Some DDD to Your ASP.NET MVC, OK?
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
 
Perl6 DBDI YAPC::EU 201008
Perl6 DBDI YAPC::EU 201008Perl6 DBDI YAPC::EU 201008
Perl6 DBDI YAPC::EU 201008
 
Workflow Yapceu2010
Workflow Yapceu2010Workflow Yapceu2010
Workflow Yapceu2010
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
 
Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software Craftsmanship
 
04 managing the database
04   managing the database04   managing the database
04 managing the database
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design Patterns
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Geecon09: SOLID Design Principles
Geecon09: SOLID Design PrinciplesGeecon09: SOLID Design Principles
Geecon09: SOLID Design Principles
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
 
Implementing The Open/Closed Principle
Implementing The Open/Closed PrincipleImplementing The Open/Closed Principle
Implementing The Open/Closed Principle
 
Functional programming in C#
Functional programming in C#Functional programming in C#
Functional programming in C#
 
The Open Closed Principle - Part 1 - The Original Version
The Open Closed Principle - Part 1 - The Original VersionThe Open Closed Principle - Part 1 - The Original Version
The Open Closed Principle - Part 1 - The Original Version
 
OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++
 
Object-oriented design principles
Object-oriented design principlesObject-oriented design principles
Object-oriented design principles
 
Open Closed Principle kata
Open Closed Principle kataOpen Closed Principle kata
Open Closed Principle kata
 
Metaprogramming JavaScript
Metaprogramming  JavaScriptMetaprogramming  JavaScript
Metaprogramming JavaScript
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
 

Viewers also liked

Viewers also liked (17)

Professional-grade software design
Professional-grade software designProfessional-grade software design
Professional-grade software design
 
Practical Enterprise Application Development
Practical Enterprise Application DevelopmentPractical Enterprise Application Development
Practical Enterprise Application Development
 
Object Oriented Concepts in Real Projects
Object Oriented Concepts in Real ProjectsObject Oriented Concepts in Real Projects
Object Oriented Concepts in Real Projects
 
SOLID PRINCIPLES
SOLID PRINCIPLESSOLID PRINCIPLES
SOLID PRINCIPLES
 
Solid principles
Solid principlesSolid principles
Solid principles
 
A Checklist for Design Reviews
A Checklist for Design ReviewsA Checklist for Design Reviews
A Checklist for Design Reviews
 
Applying Design Principles in Practice
Applying Design Principles in PracticeApplying Design Principles in Practice
Applying Design Principles in Practice
 
SOLID Principles part 2
SOLID Principles part 2SOLID Principles part 2
SOLID Principles part 2
 
Grasp
GraspGrasp
Grasp
 
S.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software ArchitectsS.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software Architects
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
The SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design PatternsThe SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design Patterns
 
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)
 
Solid principles
Solid principlesSolid principles
Solid principles
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design Patterns
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
 

Similar to Refactoring to SOLID Code

SOLID design principles in Ruby
SOLID design principles in RubySOLID design principles in Ruby
SOLID design principles in Ruby
Anil Wadghule
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
Bill Buchan
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
Hammad Rajjoub
 

Similar to Refactoring to SOLID Code (20)

Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
 
Bdd with m spec
Bdd with m specBdd with m spec
Bdd with m spec
 
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
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
 
SOLID design principles in Ruby
SOLID design principles in RubySOLID design principles in Ruby
SOLID design principles in Ruby
 
Action-Domain-Responder: A Refinement of MVC
Action-Domain-Responder: A Refinement of MVCAction-Domain-Responder: A Refinement of MVC
Action-Domain-Responder: A Refinement of MVC
 
Restructuring rails
Restructuring railsRestructuring rails
Restructuring rails
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Architecting modern Android apps
Architecting modern Android appsArchitecting modern Android apps
Architecting modern Android apps
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016
 
SOLID Design Principles for Test Automaion
SOLID Design Principles for Test AutomaionSOLID Design Principles for Test Automaion
SOLID Design Principles for Test Automaion
 
Commonly used design patterns
Commonly used design patternsCommonly used design patterns
Commonly used design patterns
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
 
Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719
Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719
Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Ibm db2update2019 ibm db2 dev ops experience
Ibm db2update2019   ibm db2 dev ops experienceIbm db2update2019   ibm db2 dev ops experience
Ibm db2update2019 ibm db2 dev ops experience
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
 

More from Adil Mughal

Web Development using ASP.NET MVC at HEC
Web Development using ASP.NET MVC at HECWeb Development using ASP.NET MVC at HEC
Web Development using ASP.NET MVC at HEC
Adil Mughal
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp Net
Adil Mughal
 

More from Adil Mughal (11)

Write cleaner, maintainable, and testable code in Android with MVVM
Write cleaner, maintainable, and testable code in Android with MVVMWrite cleaner, maintainable, and testable code in Android with MVVM
Write cleaner, maintainable, and testable code in Android with MVVM
 
Code Sharing Between Windows Phone/Store Apps
Code Sharing Between Windows Phone/Store AppsCode Sharing Between Windows Phone/Store Apps
Code Sharing Between Windows Phone/Store Apps
 
Community Contribution Experience
Community Contribution ExperienceCommunity Contribution Experience
Community Contribution Experience
 
Web Development using ASP.NET MVC at HEC
Web Development using ASP.NET MVC at HECWeb Development using ASP.NET MVC at HEC
Web Development using ASP.NET MVC at HEC
 
Web development using ASP.NET MVC
Web development using ASP.NET MVC Web development using ASP.NET MVC
Web development using ASP.NET MVC
 
Quality Assurance in SDLC
Quality Assurance in SDLCQuality Assurance in SDLC
Quality Assurance in SDLC
 
2 Day - WPF Training by Adil Mughal
2 Day - WPF Training by Adil Mughal2 Day - WPF Training by Adil Mughal
2 Day - WPF Training by Adil Mughal
 
What's New in Visual Studio 2010
What's New in Visual Studio 2010What's New in Visual Studio 2010
What's New in Visual Studio 2010
 
DevNext - How we build applications in Industry
DevNext - How we build applications in IndustryDevNext - How we build applications in Industry
DevNext - How we build applications in Industry
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp Net
 
Windows 7 For Geeks
Windows 7 For GeeksWindows 7 For Geeks
Windows 7 For Geeks
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Refactoring to SOLID Code

  • 1. Emerging .NET Devs October User Group Meeting Design Principles & Practices Adil Ahmed Mughal Zubair Ahmed
  • 2. Refactoring to SOLID Code Emerging .NET Devs
  • 3. Session => Refactoring to SOLID Code What You must already know: - Object Oriented Programming Language such as Java, C++, C# - Professional Experience What You will learn today: - Good Practices - OO Principles Sponsors:
  • 4. Speaker => Adil Ahmed Mughal Affiliations: Contact Information: adil.mughal@live.com @adilamughal http://www.adilmughal.com
  • 5. Agenda This is not a single side talk, its discussion! Promise me that you will raise hand when you have query? • How You Code Today? • What is Bad Design? • What would You Call a Good Design? • SOLID Principles!
  • 6. How You Code Today? • Do you care about design principles or patterns? • Anti-patterns? • Is your code Agile? • Do you Refactor your code? • Is your code design bad or good?
  • 7.
  • 8. Bad design is... Needless Rigid Complexity Needless Fragile Repetition Immobile Viscous
  • 9.
  • 10.
  • 11. What would You Call a Good Design? • Reliability • Flexibility • Separations of Concerns • Reusability • Maintainability
  • 12. SOLID Object Oriented Principles Introduced by Robert C. Martin in early 2000s
  • 13. SOLID Principles • S – Single Responsibility Principle (SRP) • O – Open Closed Principle (OCP) • L – Liskov Substitution Principle (LSP) • I – Interface Segregation Principle (ISP) • D – Dependency Inversion Principle (DIP)
  • 15.
  • 16. The Single Responsibility Principle "A responsibility is a reason to change, a class or module should have one, and only one, reason to change."
  • 17. The Single Responsibility Principle • “There should never be more than one reason for a class to change.” • More responsibilities => More likelihood of change • Dijkstra’s SoC: separation of concerns • Applies on every level of code • Solves the naming dilemma
  • 18. Trade Validator Trade Validator DB Trade What is wrong here: Changes if DB changes or Business Logic Changes
  • 19. Refactored Trade Validator Trade Trade Validator Source Trade DB What's its job? Classes must have an identifiable single responsibility.
  • 20.
  • 22. The Open Closed Principle “Software Entities (Classes, Modules, Functions, etc.) should be open for extension, but closed for modification”
  • 23. The Open Closed Principle • Modules that conform to the open-closed principle have two primary attributes – Open For Extension • behavior of the module can be extended – Closed for Modification • The source code of such a module is inviolate • The normal way to extend the behavior of a module is to make changes to that module. How can these two opposing attributes be resolved?
  • 24. OCP – Change behavior without changing code? • Abstraction is the key to achieve it Client Server Closed Client
  • 25. OCP – Change behavior without changing code? Client Abstract Server Server Open Client
  • 26.
  • 28. Liskov Substitution Principle “Functions that reference a base class must be able to use objects of derived classes without knowing it."
  • 29.
  • 31. Interface Segregation Principle “Clients should not be forced to depend upon interfaces that they do not use.” • Prefer small, cohesive interfaces to fat interfaces
  • 32.
  • 34. Dependency Inversion Principle “High level modules should not depend upon low level modules. Both should depend upon abstractions. “ “Abstractions should not depend upon details. Details should depend upon abstractions.”
  • 35. Trade Validator Introduce stability High Level (Less Stable) with abstraction Trade Trade Validator Source Trade Low Level DB (More Stable)
  • 36. Better Trade Validator Trade Validator <Interface> ITradeSource Trade DbTradeSource DB
  • 37. Extensible Trade Validator <Interface> TradeValidator ITradeSource Trade DbTradeSource WSTradeSource DB Cloud
  • 38.
  • 40. Actions => From Now On Learn, Practice and Make it your Habit Links: - ObjectMentor.com - Practices and Patterns on MSDN Books:
  • 41. References • Combatting Software Entropy using Design Principles and Practices – Hammad Rajjoub – TechEd ME • Agile Principles, Patterns and Practices using C# by Robert.C.Martin • Special thanks for motivational poster images by NimblePros
  • 42. Thank You! Refactoring to SOLID Code Emerging .NET Devs