Emerging .NET DevsOctober User Group MeetingDesign Principles &PracticesAdil Ahmed MughalZubair Ahmed
Refactoring to SOLID Code      Emerging .NET Devs
Session => Refactoring to SOLID CodeWhat You must already know:- Object Oriented Programming Language such as Java, C++, C...
Speaker => Adil Ahmed MughalAffiliations:Contact Information:     adil.mughal@live.com     @adilamughal     http://www.adi...
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?• Do you care about design principles or patterns?• Anti-patterns?• Is your code Agile?• Do you Refacto...
Bad design is...                         Needless  Rigid                        Complexity                         Needles...
What would You Call a Good Design?• Reliability• Flexibility• Separations of Concerns• Reusability• Maintainability
SOLID    Object Oriented PrinciplesIntroduced by Robert C. Martin in           early 2000s
SOLID Principles• S – Single Responsibility Principle (SRP)• O – Open Closed Principle (OCP)• L – Liskov Substitution Prin...
Single Responsibility Principle            (SRP)
The Single Responsibility Principle"A responsibility is a reason to change, a class ormodule should have one, and only one...
The Single Responsibility Principle• “There should never be more than one reason for a  class to change.”• More responsibi...
Trade Validator         Trade        Validator                                       DBTrade        What is wrong here: Ch...
Refactored Trade Validator           Trade                                         Trade          Validator               ...
The Open-Closed Principle (OCP)
The Open Closed Principle“Software Entities (Classes, Modules, Functions,etc.) should be open for extension, but closed fo...
The Open Closed Principle• Modules that conform to the open-closed principle have  two primary attributes   – Open For Ext...
OCP – Change behavior without           changing code?• Abstraction is the key to achieve it      Client                  ...
OCP – Change behavior without       changing code?Client                   Abstract                          Server       ...
Liskov Substitution Principle           (LSP)
Liskov Substitution Principle“Functions that reference a base class must beable to use objects of derived classes withoutk...
Interface Segregation Principle             (ISP)
Interface Segregation Principle“Clients should not be forced to depend uponinterfaces that they do not use.”• Prefer small...
Dependency Inversion Principle           (DIP)
Dependency Inversion Principle“High level modules should not depend upon lowlevel modules. Both should depend uponabstract...
Trade Validator                                              Introduce stabilityHigh Level (Less Stable)                  ...
Better Trade ValidatorTrade Validator                            <Interface>                           ITradeSourceTrade  ...
Extensible Trade Validator                                 <Interface>TradeValidator                   ITradeSourceTrade  ...
DEMOLet’s Refactor!
Actions => From Now On               Learn, Practice and Make it your HabitLinks:- ObjectMentor.com- Practices and Pattern...
References• Combatting Software Entropy using Design Principles  and Practices – Hammad Rajjoub – TechEd ME• Agile Princip...
Thank You!Refactoring to SOLID Code     Emerging .NET Devs
Refactoring to SOLID Code
Refactoring to SOLID Code
Refactoring to SOLID Code
Refactoring to SOLID Code
Refactoring to SOLID Code
Refactoring to SOLID Code
Refactoring to SOLID Code
Refactoring to SOLID Code
Refactoring to SOLID Code
Upcoming SlideShare
Loading in …5
×

Refactoring to SOLID Code

4,370 views

Published on

"Refactoring to SOLID Code" session presentation from
Emerging .NET Devs - October 2011 User Group Meeting.

Please note that this presentation has been simplified for publishing.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,370
On SlideShare
0
From Embeds
0
Number of Embeds
1,362
Actions
Shares
0
Downloads
107
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Refactoring to SOLID Code

  1. 1. Emerging .NET DevsOctober User Group MeetingDesign Principles &PracticesAdil Ahmed MughalZubair Ahmed
  2. 2. Refactoring to SOLID Code Emerging .NET Devs
  3. 3. Session => Refactoring to SOLID CodeWhat You must already know:- Object Oriented Programming Language such as Java, C++, C#- Professional ExperienceWhat You will learn today:- Good Practices- OO PrinciplesSponsors:
  4. 4. Speaker => Adil Ahmed MughalAffiliations:Contact Information: adil.mughal@live.com @adilamughal http://www.adilmughal.com
  5. 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. 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. 7. Bad design is... Needless Rigid Complexity Needless Fragile RepetitionImmobileViscous
  8. 8. What would You Call a Good Design?• Reliability• Flexibility• Separations of Concerns• Reusability• Maintainability
  9. 9. SOLID Object Oriented PrinciplesIntroduced by Robert C. Martin in early 2000s
  10. 10. 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)
  11. 11. Single Responsibility Principle (SRP)
  12. 12. The Single Responsibility Principle"A responsibility is a reason to change, a class ormodule should have one, and only one, reasonto change."
  13. 13. 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
  14. 14. Trade Validator Trade Validator DBTrade What is wrong here: Changes if DB changes or Business Logic Changes
  15. 15. Refactored Trade Validator Trade Trade Validator SourceTrade DB Whats its job? Classes must have an identifiable single responsibility.
  16. 16. The Open-Closed Principle (OCP)
  17. 17. The Open Closed Principle“Software Entities (Classes, Modules, Functions,etc.) should be open for extension, but closed formodification”
  18. 18. 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?
  19. 19. OCP – Change behavior without changing code?• Abstraction is the key to achieve it Client Server Closed Client
  20. 20. OCP – Change behavior without changing code?Client Abstract Server Server Open Client
  21. 21. Liskov Substitution Principle (LSP)
  22. 22. Liskov Substitution Principle“Functions that reference a base class must beable to use objects of derived classes withoutknowing it."
  23. 23. Interface Segregation Principle (ISP)
  24. 24. Interface Segregation Principle“Clients should not be forced to depend uponinterfaces that they do not use.”• Prefer small, cohesive interfaces to fatinterfaces
  25. 25. Dependency Inversion Principle (DIP)
  26. 26. Dependency Inversion Principle“High level modules should not depend upon lowlevel modules. Both should depend uponabstractions. ““Abstractions should not depend upon details.Details should depend upon abstractions.”
  27. 27. Trade Validator Introduce stabilityHigh Level (Less Stable) with abstraction Trade Trade Validator Source Trade Low Level DB (More Stable)
  28. 28. Better Trade ValidatorTrade Validator <Interface> ITradeSourceTrade DbTradeSource DB
  29. 29. Extensible Trade Validator <Interface>TradeValidator ITradeSourceTrade DbTradeSource WSTradeSource DB Cloud
  30. 30. DEMOLet’s Refactor!
  31. 31. Actions => From Now On Learn, Practice and Make it your HabitLinks:- ObjectMentor.com- Practices and Patterns on MSDNBooks:
  32. 32. 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
  33. 33. Thank You!Refactoring to SOLID Code Emerging .NET Devs

×