Rules Have Reasons (Always Ask Why)

Publicado 2024-07-17
What are the reasons that underlie the rules? Why should we use one technique over another? What class of problems are we solving?

đź“™ BUY MY BOOK
theobjectorientedway.com/

RELATED VIDEOS:
   • The Only Time You Should Use Polymorp...  
   • Only Use Inheritance If You Want Both...  
   • Liskov Substitution Principle  
   • When Microsoft Violated Liskov Substi...  
   • Covariance and Contravariance  
   • Depend on Abstractions not Concretion...  

CONTENTS
00:00 The problem
02:39 Static typing
04:12 Overloading
04:45 Subtype Polymorphism
06:13 My Book
06:27 Inheritance
08:28 Replace Conditional With Polymorphism
09:36 Type Testing is a Code Smell
10:30 Dependency injection
11:02 Depend on abstractions, not on concretions
11:12 Composition over inheritance
11:20 Conclusion

SOURCES:
sandimetz.com/99bottles
   • "Making Impossible States Impossible"...  
blog.cleancoder.com/uncle-bob/2014/06/20/MyLawn.ht…
sandimetz.com/blog/2016/1/20/the-wrong-abstraction
sandimetz.com/blog/2016/6/9/make-everything-the-sa…

Todos los comentarios (21)
  • @zerg-zx5rx
    Based on my experience, it's often because they don't care rather than not understanding the reasons behind it. Many developers I've worked with stick with what works without questioning it. You simply can't teach someone who doesn't want to learn.
  • I love your reason for static typing. Basically we should make invalid states impossible
  • A powerful approach (that I've also seen you take several times in your videos) is to start with a problem. Present a scenario we want to model, implement it naively, then explore shortcomings of said naive solution. Then you can swoop in with the fancy pattern/guideline/principle and show how it saves the day. You've got justification, intended use case(s) and deeper understanding all in one neat package. For bonus points, also explore the limitations/tradeoffs inherent to the "better way" for a more well-rounded engagement with the topic.
  • @ramongus1996
    I would love to deep dive into point 5. Replace conditional with polymorphism. Great video, thanks!
  • Don't make another mistake in your teaching - provide code examples for all of these cases. Apart from that, you're brilliant, thank you.
  • @ogookafor2137
    Alot of things here opened my eyes to alot of WHYs I haven't asked. Thanks again. Still rhe best.
  • Videos like this are invaluable. Concerning type testing, I still believe there is a case for subtyping even when you have pattern matching and exhaustive switch statements (I count implementing traits or protocols/interfaces as subtyping): You need to define whether it is more likely to have an explosion of cases or an explosion of decisions. With subtyping, every time you add a decision, you need to implement a new method for every subtype; With conditionals, every time you add a type, you need to add a new case for every decision you make. It is a trade off. Concerning class hierarchies and multi-level inheritance, the best example I have in mind is biology. Every developer has heard the analogy of animals, mammals, etc. (which is truly terrible, it should disappear from books and tutorials). Biologists and palaeontologists literally break the tree of life every Tuesday! Classifications are arbitrary and, like analogies, they tend to break when you include more cases or more details. When building any kind of hierarchy, it should be expected that it is going to change. And changing class hierarchies is not a trivial refactor.
  • 6) with exhaustive switches/conditionals you need to know all of the possible implementations at compile time. By using subtype polymorphism you could load a valid impl at runtime. Wonderful for something like an DB interface where you can't know of every possible impl. Not so great for typical application code that IS known at compile time.
  • @Max-zn7md
    A video talking about dependency injection (object composition, dependencies lifetime, interception and di containers) would be very cool
  • You are my role model, I was always searching for someone who can guide, and seems like the search is over now :) Thank you for such good content.
  • I'm really liking your take on these OOP concepts. Even after studying computer science at university in the early 2000s, reading dozens of books on the subject of object oriented programming and design and being a professional software developer since 2007, I find your approach on the subject very refreshing and interesting. Bought the book : )
  • @susseduud
    Like I feel you've alluded to: all roads lead towards FP. I have a background and interests more in FP, procedural, and "make it impossible, not testable" types of software. I wanted to drop in and say that as much as I value the OOP-centric videos and concepts (I love your academic and thorough approach in your videos), it can sometimes be challenging to convert the OOP way of thinking to a "general", non OOP, way of thinking. Despite enjoying this challenge, I would love to hear more ideas and concepts that apply more to procedural world of code. Anyway, thank you for making these videos. I watch all of them and appreciate how they encourage critical thinking.
  • I wish I could read your book and learn from it but in Iran we cannot purchase. but I learn from your awesome videos and I'm grateful for this ❤
  • @chris407x
    Great explanation (around 4 minutes in) about how static typing makes conditional statements unnecessary. I have been doing this for a while, but this is a clear explanation of why it works.
  • @johnekare8376
    Great video, as always! I would love a deep dive on each of these - got the book now, but I really like the video format, and you are an excellent communicator.
  • @sniperated
    This is gold, but I hope this is the first of many videos. To me, the best way of learning something is to understand the reason why it is like that. I always fought against the "it is like that, take it as it is" approach during my university studies. And everybody is learning like this, just memorizing without asking "ok, but why". As a .net developer it was hard to understand why we had webforms, why do we have http, what's soap and why everybody despise it. Luckily there are a couple of videos on .net evolution that answered many of these questions. After years of studying math, I had the chance to attend to a "math's history" course. It was so satisfying to learn how we slowly figured how to solve equations, why we write x^2 and so on
  • Amazing video as always. I bought the book which I'm sure is gonna be so worth it and also to thank you for all the amazing content you gave us access to for free. Thank you for all of that !