Learn the dependency inversion principle.

And stop monkey-patching.

High-level modules should not depend on low-level modules. Both should depend on abstractions. Also, abstractions shouldn’t depend on details. Details should depend on abstractions. These abstract interfaces become the contract on how two modules will communicate. Each module can change internally, but as long as they implement the abstract interface, they will still work together.

No class should derive from a concrete class. If you derive from a concrete class, you become more dependent on specific implementations.

No method should override an implemented method. This is a sure-fire way to find surprises further down the line. People expect one behavior, and then you’ve gone and changed the behavior. Bugs will follow.

Variable instantiation should use factories or a Dependency Injection framework.

Reducing dependencies and relying on abstracts leads to code that is easier to test, simpler to change, and more straightforward to support.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: