SlideShare a Scribd company logo
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?
Refactoring to SOLID Code
Bad design is...
                         Needless
  Rigid
                        Complexity

                         Needless
 Fragile
                        Repetition

Immobile


Viscous
Refactoring to SOLID Code
Refactoring to SOLID Code
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)
Refactoring to SOLID Code
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.
Refactoring to SOLID Code
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
Refactoring to SOLID Code
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."
Refactoring to SOLID Code
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
Refactoring to SOLID Code
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
Refactoring to SOLID Code
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

PPTX
Do we need SOLID principles during software development?
PPTX
Refactoring Applications using SOLID Principles
KEY
"SOLID" Object Oriented Design Principles
PPTX
SOLID Software Principles with C#
PDF
Solid principles of oo design
PPTX
Writing Maintainable Software Using SOLID Principles
PPTX
Single Responsibility Principle
PDF
Object Oriented Design Principles
Do we need SOLID principles during software development?
Refactoring Applications using SOLID Principles
"SOLID" Object Oriented Design Principles
SOLID Software Principles with C#
Solid principles of oo design
Writing Maintainable Software Using SOLID Principles
Single Responsibility Principle
Object Oriented Design Principles

What's hot (20)

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

Viewers also liked (17)

PPTX
Professional-grade software design
PPTX
Practical Enterprise Application Development
PDF
Object Oriented Concepts in Real Projects
PDF
SOLID PRINCIPLES
PPTX
Solid principles
PDF
A Checklist for Design Reviews
PDF
Applying Design Principles in Practice
PPTX
SOLID Principles part 2
PPTX
PPTX
S.O.L.I.D. Principles for Software Architects
PPT
SOLID Design Principles
PPTX
The SOLID Principles Illustrated by Design Patterns
PPTX
Building Secure User Interfaces With JWTs (JSON Web Tokens)
PPT
Solid principles
PPT
SOLID principles
PDF
SOLID Principles and Design Patterns
PDF
Build Features, Not Apps
Professional-grade software design
Practical Enterprise Application Development
Object Oriented Concepts in Real Projects
SOLID PRINCIPLES
Solid principles
A Checklist for Design Reviews
Applying Design Principles in Practice
SOLID Principles part 2
S.O.L.I.D. Principles for Software Architects
SOLID Design Principles
The SOLID Principles Illustrated by Design Patterns
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Solid principles
SOLID principles
SOLID Principles and Design Patterns
Build Features, Not Apps
Ad

Similar to Refactoring to SOLID Code (20)

PPTX
C:\Fakepath\Combating Software Entropy 2
PPTX
C:\Fakepath\Combating Software Entropy 2
PPTX
Improving The Quality of Existing Software
PPT
Object Oriented Analysis and Design with UML2 part2
PPTX
Improving the Quality of Existing Software
PPTX
SOLID Principles
PPTX
Becoming a better developer by using the SOLID design principles
PDF
Software design principles - jinal desai
PPTX
Establishing a SOLID Foundation
PPTX
Improving the Quality of Existing Software - DevIntersection April 2016
PPTX
Design Principles
PPT
The OO Design Principles
PPTX
Combating software entropy 2-roc1-
PPTX
Improving the Design of Existing Software
PDF
Design Principles SOLID_ para el desarrollo de software
PPTX
Soild principles
PPTX
.NET Architecture for Enterprises
PDF
Agile Modelling Architecture
PDF
Design for Testability
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
Improving The Quality of Existing Software
Object Oriented Analysis and Design with UML2 part2
Improving the Quality of Existing Software
SOLID Principles
Becoming a better developer by using the SOLID design principles
Software design principles - jinal desai
Establishing a SOLID Foundation
Improving the Quality of Existing Software - DevIntersection April 2016
Design Principles
The OO Design Principles
Combating software entropy 2-roc1-
Improving the Design of Existing Software
Design Principles SOLID_ para el desarrollo de software
Soild principles
.NET Architecture for Enterprises
Agile Modelling Architecture
Design for Testability

More from Adil Mughal (11)

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

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
1. Introduction to Computer Programming.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
A Presentation on Artificial Intelligence
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPT
Teaching material agriculture food technology
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MIND Revenue Release Quarter 2 2025 Press Release
1. Introduction to Computer Programming.pptx
Encapsulation_ Review paper, used for researhc scholars
Building Integrated photovoltaic BIPV_UPV.pdf
A comparative analysis of optical character recognition models for extracting...
A Presentation on Artificial Intelligence
Per capita expenditure prediction using model stacking based on satellite ima...
Network Security Unit 5.pdf for BCA BBA.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Teaching material agriculture food technology
Heart disease approach using modified random forest and particle swarm optimi...
Machine learning based COVID-19 study performance prediction
Digital-Transformation-Roadmap-for-Companies.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
SOPHOS-XG Firewall Administrator PPT.pptx
Encapsulation theory and applications.pdf

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: [email protected] @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?
  • 8. Bad design is... Needless Rigid Complexity Needless Fragile Repetition Immobile Viscous
  • 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)
  • 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.
  • 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
  • 28. Liskov Substitution Principle “Functions that reference a base class must be able to use objects of derived classes without knowing it."
  • 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
  • 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
  • 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