Interface Segregation Principle (Php SOLID Design)

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ธ.ค. 2019
  • Interface segregation is a software design principle and most notable as the I in #SOLID Design Principles.
    In object oriented programming, an interface is synonymous to a contract.
    When a class implements an interface, it is required to implement all methods defined in that interface.
    The interface segregation principle states that:
    ~~~~~~~~~~~~~~
    "No client should not be forced to depend on methods it does not use".
    ~~~~~~~~~~~~~~
    The "client" within this principle is referencing any any class that implements an interface.
    The given class (client) "should not be forced to depend on methods it does not use"
    This is a reference to interfaces. An interface is "forced" to depend on methods that are within an interface it implements.
    When a given interface requires the class to have a method it does not use, then we should follow this SOLID design principle and "segregate" or separate our interface into multiple, smaller interfaces so the class can implement an interface that only demands it has the methods or functions it actually uses.
    Clean Code Studio ~ Simplify!
    Clean Code Clean Life
    cleancode.studio
    #InterfaceSegregation #php #solidprinciples
    cleancode.studio/series/solid...
  • แนวปฏิบัติและการใช้ชีวิต

ความคิดเห็น • 13

  • @thehappyperson4125
    @thehappyperson4125 4 ปีที่แล้ว +7

    This guy is a saver for me, he helped me so much on reddit, even he doesn't know how much his help has meant to me. Thank you so much man.Keep uploading its just a matter of time your subs will sky rocket.

    • @CleanCodeStudio
      @CleanCodeStudio  4 ปีที่แล้ว +1

      Glad my feedback was able to help you out, thanks for the shoutout and support Rakesh! I'll keep them coming :)

  • @samualobryan652
    @samualobryan652 4 ปีที่แล้ว +6

    GOOD stuff :) To the point, direct, and extremely easy to understand!

    • @CleanCodeStudio
      @CleanCodeStudio  4 ปีที่แล้ว +1

      Thanks Samual Obryan :)
      Glad it was a helpful and concise. Interface Segregation (in my opinion) is the simplest design principle out of all SOLID principles ~ but it was a good one to nail down exactly what interfaces are and how they work since so many other design principles depend on interfaces (AKA contracts :)

  • @crushfire2004
    @crushfire2004 4 ปีที่แล้ว +1

    How to implement this on programming languages that doesn't have interfaces? Like JavaScript (not using typescript) or Python?

    • @CleanCodeStudio
      @CleanCodeStudio  4 ปีที่แล้ว

      Hey Deli Soetiawan, Javascript is a more flexible than Php and allows for more paradigms than Php does.
      Specifically, javascript is prototypal and treats functions as first class citizens making it much more difficult to abide by Liskovs substitution principle.
      Weighing the pros and cons of how Javascript is set up is a very deep, lengthy rabbit whole that would take multiple series to cover in depth ~ that being said I did find this article that you may find of some interest.
      aspiringcraftsman.com/2011/12/31/solid-javascript-the-liskov-substitution-principle/

    • @crushfire2004
      @crushfire2004 4 ปีที่แล้ว +1

      @@CleanCodeStudio kinda agreed that JS is a wild west of programming language, no such thing like PSR/PEP so I don't expect much also for using SOLID in it

    • @CleanCodeStudio
      @CleanCodeStudio  4 ปีที่แล้ว +1

      ​@@crushfire2004 Hahhaha, "wild west" of programming ~ that's gold and spot on in several regards.
      Everything that makes javascript seem "wild west" like, ironically, is what makes js soooo danged powerful.
      If you're looking for the "technically best" design patterns for managing your dependencies in javascript (AKA managing complexity), I recommend looking into functional programming.
      That being said, I am very hesitantly recommending implementing javascript via the functional paradigm. At the end of the day, from a technical standpoint, the functional paradigm - in my opinion - is the most powerful and reliable paradigm (Paradigm being defined as repeated habits we implement) BUT if you're team doesn't understand it that point doesn't matter.
      The functional paradigm is powerful for two extremely, tightly coupled, reasons.
      1. Functional programming does NOT depend on extraneous state
      2. Functional programming can NOT mutate extraneous state (when implemented to its truest form)
      I do NOT 100% recommending functional programming, and in most scenarios would recommend against it. Within a team where the majority of team members don't understand functional programming ~ well, that's a big problem.
      That being said, javascript makes it much easier to implement functional programming than Php and if you're team (or you work alone), either already understands or are willing to learn functional programming than it is actually better than SOLID design principles (my opinion, but mathematically speaking ~ functional programming depends on less reducing non-intrinsic domain complexity).
      Even if functional programming is not a viable option for your or your team, I do recommend learning up on it ~ understanding the implementation of functional programming in javascript is hugely beneficial for understanding javascript in its entirety.
      Here's a great resource that has helped me tremendously for understanding functional design.
      mostly-adequate.gitbooks.io/mostly-adequate-guide/

  • @betweencodes
    @betweencodes ปีที่แล้ว

    You could have added here a class called HtmlFile that implements both File and Html to show how that is done. Html class here is left hanging, poor guy.

  • @rihulfaakbar2261
    @rihulfaakbar2261 4 ปีที่แล้ว

    Why should I use interface? for what purpose? pros and cons?

    • @CleanCodeStudio
      @CleanCodeStudio  4 ปีที่แล้ว

      Interfaces contractually bind a class to implement or have a method.
      Methods represent behavior.
      By using interfaces you are contractually binding your classes to have certain behavior.
      You don't need to know how that behavior is implemented, just that it's there.
      FileInterface
      Enforces parse() method
      Class HtmlFile implements FileInterface
      Class JsonFile implements FileInterface
      Class CsvFile implements FileInterface
      If HtmlFile, JsonFile, Or CsvFile don't have a parse method, Php won't run.
      The actual implementation for the parse method differs based on the given file type, but we know that every single class implementing can "parse()" its file type.
      We know each class can parse() itself, we don't know how the given class actually implements the parse() method. Simply that it exists on each class.

    • @rihulfaakbar2261
      @rihulfaakbar2261 4 ปีที่แล้ว

      So, basically we don't need to extends class but just implements their interface is enough?
      Could you please make a video about implementation of interfaces in framework, for example slim version 3 ( i prefer v3 because v4 is too complicated for me, redirecting etc)

    • @CleanCodeStudio
      @CleanCodeStudio  4 ปีที่แล้ว

      Honestly, as difficult as Slim 4 may seem in comparison to Slim 3 ~ it's due to how well Slim 4 uses interfaces (Specifically PSR AKA Php Standard Recommendations Interfaces).
      At this point, it doesn't feel like we'll ever do a Slim 3 tutorial.