1 / 21

Learning SOLID Principles Using C#

Learning SOLID Principles Using C#. Dhananjay Kumar Infragistics Consultant Microsoft MVP, C# Corner MVP http :// debugmode.net. I am Dhananjay Kumar. 6 times Microsoft MVP Infragistics Consultant 7 times C- SharpCorner MVP @ debug_mode Blog : http ://debugmode.net. Agenda.

tomr
Download Presentation

Learning SOLID Principles Using C#

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Learning SOLID Principles Using C# Dhananjay Kumar Infragistics Consultant Microsoft MVP, C# Corner MVP http://debugmode.net

  2. I am Dhananjay Kumar • 6 times Microsoft MVP • Infragistics Consultant • 7 times C-SharpCorner MVP • @debug_mode • Blog : http://debugmode.net

  3. Agenda SOLID Principles

  4. SOILD Principles

  5. SOILD Principles

  6. SRP

  7. SRP • Responsibilities examples • Persistence • Validation • Notification • Error Handling • Logging • Class Selection / Instantiation • Formatting • Parsing • Mapping • Sending mail • Printing etc. There are more than on functions (reason to change) in the class. Even if we change one of the functions, we will have to RETEST the whole class. Assume we have four functions(reason to change) in a class. Change in single function will cause re-testing of all four functions, which is not desirable. SRP avoids it.

  8. SRP Demo

  9. OCP Class should be designed in such a way that, it should be Closed for modification Open for extension

  10. OCP Consider a scenario • There is a class with the responsibility to calculate discount • At the time of the class designing you have three rules for the discount offer. • Discounts are calculated on various rulesand that can be implemented as shown below , • if(rule 1 ) then give discount 1 • else if(rule 2 ) then give discount 2 • else if (rule 3) then give discount 3 • and so on ……….. • If a new rule is coming in the system , you will go and add new else if in the above code • By adding new else if , you will modify the existing class. • Once modified you have to again test all the rules for the better design

  11. OCP Demo

  12. LSP Class should be designed in such a way that- object of derived class should able to replace object of the base class without bringing any error in the system or modifying the behavior of the base class. If S is subset of T then, object of T could be replaced by object of S without impacting the program and bringing any error in the system

  13. LSP • classical : • is- a relationship • LS principle : • is-substitute for relationship Class should be designed in such a way that- Inheritance

  14. LSP Demo

  15. ISP ISP splits interfaces which are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them The ISP says , clients should not be forced to depend on the methods they do not use.

  16. ISP

  17. ISP Demo

  18. DIP Abstractions should not depend on details. Details should depend on abstractions. High-level modules should not depend on low-level modules. Both should depend on abstractions.

  19. DIP Let us understand with the Demo

  20. Summary • Single Responsibility principle • Open-Closed principle • Liskov Substitution principle • Interface Segregation principle • Dependency Inversion principle

  21. What Infragistics can offer you? • We welcome all of you to take advantage of a FREE 30 Day Trial by downloading the product at: http://www.infragistics.com/products/ultimate/download • Please reach out to us at Sales-India@infragistics.comfor any follow up questions you may have. We welcome the opportunity to assist you.

More Related