Decouple dependencies

Decouple via abstraction and extensions.

By having classes depend on a common interface to implement, we introduce cohesion while repelling coupling.

If Entity A is coupled with Entity B then Entity A will not be able to function without Entity B, even if it was replaced with another similar Entity. Entity A would need to be refactored to use the new Entity

SOLID Principles

A set of guidelines to help us write Maintainable, decoupled, flexible Object Oriented Code. Created by Robert C. Martin, also known as Uncle Bob amongst developers. Highly respected and has a bunch of books on writing clean code.

S for Single Responsibility

Each class has is responsible for one thing or task…

Trying to keep everything modular and atomic.

O for Open-Closed

States that software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.

Don’t modify if you want to changes something, extend and override! // Inheritance and Overriding for the win.

We use this Open for Extension Closed for Modification as a way to avoid disgusting if-elif statements.

image.png

L for Liskov Substitution

It States that objects should be replaceable with instances of their sub types without altering the program.

If S is a subtype of T, then objects of type T may be replaced (or substituted) with objects of type S.

<aside> 💡

In Python overridden methods in Python can have a different signature than the method they’re overriding from the super type, as long as the name is the same.

</aside>