Skip to content

Latest commit

 

History

History
68 lines (44 loc) · 3.58 KB

week-04.md

File metadata and controls

68 lines (44 loc) · 3.58 KB

WEEk 04 - L.I.D. (Chapters 9, 10, and, 11)

Week Three Video

Liskov Substitution Principle

  • LSP is primarily about guiding the use of inheritance.
  • Every "subtype" should be able to be used as its parent type "all the way up the chain"
  • In the first image this is done well

example of LSP as intended

  • in the second this is not

example of the violation of LSP

  • the example in the book is long and convoluted
  • suffice it to say a simple violation of subsitutibility can cause a system's architecture to baloon out of control.

Interface Segregation Principle

Picture of the BAD way: Picture of the BAD way

Better: add more interfaces!!

Better: add more interfaces!!

  • In general it is considered harmful to depend on code taht you don't actually use.
  • In development time it can cause unnecessary recompilations and redeployments.
    • Great example: windows nano server
    • example of "old server" system just for the image
    • content of this example to be discussed live in the show. Stay tuned for incoming youtube link after tomorrow night.... or in theory it is already there and I never removed this line of text. That souds like me.
  • Something that carries baggage that you don't need can cause you troubles that you didn't expect.

Dependency Inversion Principle

  • the most flexible systems are those where source code dependencies only refer to abstractions
  • never depend on CONCRETE classes, instead always write an interface layer whan consuming something
  • good software designers and work hard to reduce the volatility of interfaces
    • example: instead of calling a database's SAVE method directly if you call it through an interface you can later swap out your database by editing the ONE file that makes calls to the concrete classes.
  • Stable software architectures are those that avoid depending on volitile concretions

DIP Summary rules

  • Don't refer to volatile concrete classes

  • Don't derive from volatile concrete classes

  • Don't override concrete functions

  • Never mention the name of anything concrete and volatile

  • The key to the DIP is to ensure that all dependencies point in one direction across the boundry line

  • note that the orange dotted lines

a picture of a non-well defined boudry system

a picture of a well-defined boudry line

  • LIVE SHOW: discuss why the second version is is better
  • Most systems will contain at least one concrete component (often called main)

Conclusion

  • DIP shows up again and again.
  • This is the most visible organizing principle
  • dependencies should cross boundry lines in one direction
  • this is referred to as "the dependency rule"