• Save
SOLID Principles part 2
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

SOLID Principles part 2

  • 872 views
Uploaded on

Of the SOLID principles, made famous by Robert C. Martin, we'll discuss the Interface Segregation Principle and the Dependency Inversion Principle. This session will explain them thoroughly and......

Of the SOLID principles, made famous by Robert C. Martin, we'll discuss the Interface Segregation Principle and the Dependency Inversion Principle. This session will explain them thoroughly and give real life examples instead of the regular customer & order examples. You'll walk away knowing what the benefits are and how to use them properly.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • I see your presentation on SOLID is incomplete, missing the Liskov Substitution Principle
    Are you sure you want to
    Your message goes here
  • Can you please send me SOLID Principles part 1 & 2 ppt to aashaikh55@gmail.com.

    Thanks in advance.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
872
On Slideshare
872
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
2
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • There are other talks that will go into Big Data and Hadoop so we’ll only do a quick overview of that right now. We’ll spend most of our time on Hive.
  • 5 basic principles of OOPDIntroduced in 2000By Robert C. Martin (Uncle Bob)Whenapplied, more likelyto have a bettermaintainableandextendable system over time.
  • Guidelines, not hard rules, not a dogmaUse common senseDon’tjustthrowthemaway
  • Add “System.Web.Applications” and implement “MembershipProvider”
  • Also doesn’t violate SRP
  • NotImplementedException
  • Also doesn’t violate SRP
  • Also doesn’t violate SRP
  • Also doesn’t violate SRP
  • Interfaces are packaged with higher-level components. They define higher-level components needs, not lower-level components behavior.
  • Tight coupling- When 2 classes depend on each other

Transcript

  • 1. Dennis van der SteltInterface Segregation PrincipleDependency Inversion PrincipleDennis van der SteltSoftware ArchitectTellushttp://bloggingabout.net/blogs/dennis/@dvdsteltdvdstelt@tellus.comPascal de JongeDevelopment LeadTellushttp://www.pazquality.com/@pdejongepdejonge@tellus.comSOLID
  • 2. Dennis van der Stelt
  • 3. Dennis van der SteltAGENDA
  • 4. Dennis van der SteltSOLIDHistory
  • 5. Dennis van der SteltGuidance
  • 6. Dennis van der SteltSOLIDFive principlesSingle Responsibility SOLID Open/ClosedLiskov Substitution Interface SegregationLearn them, love them, live by them…Dependency Inversion
  • 7. Dennis van der SteltSOLIDBooks
  • 8. Dennis van der SteltSOLIDInterface Segregation Principle
  • 9. Dennis van der SteltINTERFACE SEGREGATION PRINCIPLEclients should not be forcedto depend on methodsthey do not use
  • 10. Dennis van der SteltINTERFACE SEGREGATION PRINCIPLEtailor interfaces to individual client’s needs
  • 11. Dennis van der SteltDEMOMembership Provider
  • 12. Dennis van der SteltINTERFACE SEGREGATION PRINCIPLEpublic interface IVerifyCredentials{int MaxInvalidPasswordAttempts { get; }bool ValidateUser(string username, string password);}public interface IManageCredentials{bool ChangePassword(string oldPassword, string newPassword);int MinRequiredNonAlphanumericCharacters { get; }int MinRequiredPasswordLength { get; }string ResetPassword(string username);}public interface IManageUsers{MembershipUser CreateUser(string username, string password);bool DeleteUser(string username, bool deleteAllRelatedData);}
  • 13. Dennis van der SteltINTERFACE SEGREGATION PRINCIPLEWhy is violation of this principle a problem?introduces very fat interfacesdifficult to extend functionalityviolates single responsibility principleforced dependencies02030401
  • 14. Dennis van der Steltpublic interface IDoor{bool IsDoorOpen { get; set; }void Lock();void Unlock();}INTERFACE SEGREGATION PRINCIPLEpublic class SimpleDoor : IDoor{public bool IsDoorOpen { get; set; }public void Lock(){// Implementation here...}public void Unlock(){// Implementation here...}}
  • 15. Dennis van der Steltpublic interface ITimerFunction{void TimerFunction();}INTERFACE SEGREGATION PRINCIPLEclass AdvancedDoor : IDoor, ITimerFunction{public bool IsDoorOpen { get; set; }public void Lock() { }public void Unlock() { }public void TimerFunction(){// Implementation here...}}
  • 16. Dennis van der SteltList<IDoor> doors = new List<IDoor>(){new SimpleDoor(),new AdvancedDoor()};foreach (var door in doors){if (door is ITimerFunction)((ITimerFunction)door).TimerFunction();}INTERFACE SEGREGATION PRINCIPLE
  • 17. Dennis van der SteltSOLIDDependency Inversion Principle
  • 18. Dennis van der SteltDEPENDENCY INVERSION PRINCIPLEhigh level modules should notdepend upon low levelmodules, both should depend onabstractions.abstractions should notdepend upon details.details should depend onabstractions
  • 19. Dennis van der SteltDEPENDENCY INVERSION PRINCIPLEInversion of controlComponent AComponent BComponent C
  • 20. Dennis van der SteltDEPENDENCY INVERSION PRINCIPLEInversion of controlComponent AComponent AService<<interface>>Component BComponent AServiceComponent C<<interface>>
  • 21. Dennis van der SteltDEPENDENCY INVERSION PRINCIPLEInversion of controlComponent A Client Service<<interface>>Component BComponent AServiceComponent C<<interface>>Component D
  • 22. Dennis van der SteltDEPENDENCY INVERSION PRINCIPLEValar Morghulis
  • 23. Dennis van der SteltDEMOGame on!!!
  • 24. Dennis van der SteltDEPENDENCY INVERSION PRINCIPLEViolationspublic class SecurityService{public static User GetCurrentUser(){return Context.User;}}Dependency in static method
  • 25. Dennis van der SteltDEPENDENCY INVERSION PRINCIPLEViolationspublic class OrderProcessing{private IList<Product> FindProduct(int category){var repository = new ProductRepository();return repository.FindByCategory(category);}}Instantiating your own dependencies
  • 26. Dennis van der SteltDEPENDENCY INVERSION PRINCIPLEViolationspublic class OrderProcessing{private IList<Product> FindProduct(int category){var repository = ServiceLocator.GetInstance<IProductRepository>();return repository.FindByCategory(category);}}Asking for instantiating your dependenciesonly at the composition root
  • 27. Dennis van der SteltCOMPOSITION ROOTApplication entry pointFactory PatternLibraries & Frameworks
  • 28. Dennis van der SteltCOMPOSITION ROOTApplication entry pointFactory PatternLibraries & Frameworks
  • 29. Dennis van der SteltCOMPOSITION ROOTApplication entry pointFactory PatternLibraries & Frameworks
  • 30. Dennis van der SteltDEPENDENCY INVERSION PRINCIPLEInversion of controlHomeControllerICustomerRegistration<<interface>>CustomerRegistrationIMessageSenderFactoryMessageSenderFactory<<interface>>ICustomerRepository<<interface>>CustomerRepositoryMessageSenderBase
  • 31. Dennis van der SteltDEMODependency Injection in MVC
  • 32. Dennis van der Stelt
  • 33. Dennis van der SteltCONCLUSIONSingle Responsibility SOLID Open/ClosedLiskov Substitution Interface Seggregation Dependency Inversion
  • 34. Dennis van der Stelt34Thank youquestions?Dennis van der SteltSoftware ArchitectTellushttp://bloggingabout.net/blogs/dennis/@dvdsteltdvdstelt@tellus.comPascal de JongeDevelopment LeadTellushttp://www.pazquality.com/@pdejongepdejonge@tellus.com