Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Slow Down, Compose Yourself (PyCon AU 2015)

Slow Down, Compose Yourself (PyCon AU 2015)

As your codebase grows, you will have instances where you have code that needs to be reused. Then you think, I can do this with subclassing! Now you have a diamond-tree of problems.

Here, we’ll talk about a better way of code reuse and introducing alternate behaviour into existing classes — composition. It’ll improve how you test your code — making your test runs faster, making it easier to test exceptional cases, and making everything easier to understand.

Amber Brown (HawkOwl)

August 01, 2015
Tweet

More Decks by Amber Brown (HawkOwl)

Other Decks in Programming

Transcript

  1. One of the most common ways to do this is

    through inheritance and subclassing
  2. Multiple inheritance can lead to confusing situations, such as the

    order of the mixin declarations affecting behavour
  3. A yearly archive could be implemented as an IBlog that

    only looks at the year it was instantiated with, rather than making more complex queries