Skip to content

Instantly share code, notes, and snippets.

@alvinncx
Last active August 24, 2020 10:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvinncx/29e83e8cd61024f3ec867748612929e0 to your computer and use it in GitHub Desktop.
Save alvinncx/29e83e8cd61024f3ec867748612929e0 to your computer and use it in GitHub Desktop.
My thoughts on Sandi Metz's presentation on better OOP Design

My thoughts on Sandi Metz's presentation on better OOP Design

Youtube Link

How to write better Object Oriented code. The central claim is that OO is not a problem, but many teams are not utilising the features of OO to design better code. Her other point is also that design becomes more important late stage as code bases becomes bigger.

Takeaway points

  • Premature design is bad. Does not really add value. However when design is required later, it is too late and most people don't know how to do it properly.
  • Code that is properly abstracted should be easier to change than complex routines. However, wrongly abstracted code can also make it as difficult at complex code.
    • Typical symptoms include method hiding for no reason (copying lines of code into private methods)
  • One way to determine if code base has such a problem is to look for files that are high churn and high complexity
    • Complexity can be measured in cyclomatic complexity and lines of code
    • Santi proposes that most complexity should be inversely proportional to churn.
    • Usually occurs on files that describe the apps core business domain
  • See video for example on how code is typically made more complicated
  • See video also for how to extract classes utilising polymorphism and factory patterns.
  • Design principles
    • Objects should be be thought of as playing roles. This satisfies Liskov substitution as well.
    • Isolate the things you want to vary.
    • Use dependancy injection, but inject smartly. In her example, inject objects and behaviors, not data.
  • The problem is not OO if you need to see the entire behavior to make changes. It just means the abstraction is bad.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment