Learn the Interface Segregation Principle.

Only depend on what you use.

As applications grow over time, they get more and more features. Their interfaces become more and more complicated, as they can handle all kinds of different exceptional cases. The problem with these beasts is that making a single change can break so many things, as everything depends on the entirety of the interface.

Instead of this mess, you should prefer that systems become decoupled from each other. Do not force clients to depend on interfaces or methods they don’t use. Breaking classes and interfaces into smaller pieces means that systems can rely only on the small parts instead of everything. It is much better to depend solely on the portions you’re going to use. This way, there’s less impact on you when things change.

Watch out for big fat classes with too many methods. These massive classes can do a ton of things, but they also have a ton of reasons to change. Instead, look to have many smaller classes with much more limited interfaces. If that means you have to depend on several classes with limited interfaces, that’s better than relying on a giant class with a massive interface that can do many more things than you’ll ever need.

Choose fine-grained specific interfaces over a multipurpose interface. Think of it as preferring to use a box of tools over an elaborate swiss army knife. Use the right specialized tool for the job. It’s much easier to repair or replace one tool. If you’re just drilling holes, you don’t need support for tightening bolts and sanding edges.

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 )

Google photo

You are commenting using your Google 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: