Just imagine that you need 20 different keys on your keyring to enter your home but only one of them is actually used to unlock the door.

The Interface Segregation Principle tries to solve this problem for software.

🧵🔽
1️⃣ What does it state?

The Interface Segregation Principle (ISP) sets a pretty simple statement:

"No client should be forced to depend on methods it does not use."

The ISP applied to the extreme will result in single-method interfaces, also called role interfaces.
You can take a look at the following example to get an idea of how the ISP can be violated in one way (it's in TypeScript). interface ReportService {  ...
Can you spot the issue?

The class implementing the interface actually doesn't want to implement two of the three methods defined within the interface. But it is forced to do so because the interface is too bulky.

The client in this case is you, satisfying the interface.
2️⃣ What does it try to prevent?

Most importantly it tries to prevent:

- Confusion among client developers
- Sprawling maintenance costs

But we'll take a look to find out what this actually means now.
ℹ️ Confusion among client developers

Imagine you had to implement such a bulky interface, like above, although you only wanted to use a base class to implement employee reports.

Wouldn't you be confused that you also had to implement so much more? I would be.
It's also a sign that the base class maybe tries to do too much.

Nevertheless, you are left with the need to actually do something about the methods you didn't intend to use at all. And even the thoughts you have to put into thinking about what to do are unnecessary work.
ℹ️ Sprawling maintenance costs

Every time the interface changes, several classes implementing it need to change. And in this case, it doesn't even matter if they actually implement all of the methods.
They are forced to if the client wants their code to compile or at least run error-free at runtime.
This is a huge addition to maintenance costs. And this is a driver of unnecessary work for every client developer.
3️⃣ Fixing the issue

One way to fix the issue can now be to actually pull the interface apart, as shown below. interface EmployeeReportSer...
This is the extreme version of the ISP applied, role interfaces which all do exactly one thing.

With a little more thought, however, you can fix the issue even better, by generalizing the interface.
Take a look at the version below. Any notions of specifics were removed due to the fact that you now have a pretty generic interface, which can be implemented in many ways. interface ReportService {  ...
4️⃣ Should you care?

I'm pretty sure you already know the answer => Yes, you should.

Bulky interfaces can occur in any language, even in dynamically typed ones like JavaScript.
Although you don't have interfaces at hand, you still define, by the code you write, what you expect a client to pass to you.
Just imagine a function that takes a god object and uses several methods on that object to do its work. Everyone using your function would have to put at least something into those object's methods to make your function work.
The ISP saves you and others from putting in a lot of unnecessary work into the implementation of unwanted dependencies. And as with nearly any other principle associated with clean code, code becomes more readable and tests become better as well as more maintainable.
5️⃣ Show Your Support

You can read this thread in the form of a blog post if that suits you better. You can find the link below.

blog.oliverjumpertz.dev/isp-the-interf…
And did you know that I have a newsletter where I share valuable insights, especially on how to upskill yourself?

You can read all past issues online, so no need to subscribe directly. Test it out first.

getrevue.co/profile/oliver…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Oliver Jumpertz

Oliver Jumpertz Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @oliverjumpertz

14 Mar
Let's talk about how you can optimize your LinkedIn profile by using keywords.

This approach worked pretty well for me, and it might help you, too.

🧵🔽
1️⃣ Most Recruiters Search For Keywords

LinkedIn offers recruiters the chance to look for profiles of users by using keywords. If you ever had to search in Atlassian Jira, you know how that works approx.
If not, basically imagine it like this:

A recruiter can type in keywords and then use boolean logic, like ("engineer" OR "developer" OR "dev") AND "javascript" AND ("react" OR "vue").

LinkedIn will process this and then return a list of potential profiles for them.
Read 13 tweets
13 Mar
Imagine every device manufacturer created their own plug that only they were allowed to manufacture. You'd need at least one cable for each device to charge. Gladly we have USB as a standard.

The Dependency Inversion Principle solves this issue for software.

🧵🔽
1️⃣ What does it state?

Modules that encapsulate high-level policy should not depend upon modules that implement details. Rather, both kinds of modules should depend upon abstractions.
This may sound a little complicated, but you can break it up, as follows:

1. High-level modules should not depend on low-level modules. Both should depend on abstractions (e.g., interfaces).
Read 23 tweets
5 Mar
Code Reviews are a great way to use the experience and knowledge of a team to create good software. Not all review processes are enjoyable, though.

Here are 6 tips to make your review process better and more enjoyable for everyone!

🧵🔽 Two developers sitting at a...
1️⃣ Make Expectations Clear

A good review process should both be standardized and individual. The terms of the process should be written down and transparent for everyone on the team. Each team member should know what is expected of them and all team members should agree ...
... on the terms. Changing the terms should always be a democratic process within the team. If the team disagrees on changes or terms, it should discuss the issues until there is consent.

On the other hand, the process should be flexible enough to allow for individuality.
Read 19 tweets
18 Feb
Proof-Of-Work is the name of a cryptographic algorithm that is used for some blockchains when new blocks are to be appended to the chain.

Let's take a higher-level look at how this one works, shall we?

🧵🔽
1️⃣ The Basics

This algorithm creates a system in which one party (the prover) has to prove to one or multiple other parties (the verifiers) that they put in a certain amount of work for some purpose.
The work the prover has to put in is moderately hard to very hard, while the verifiers can pretty easily check whether the proof is correct. This creates an asymmetric system.

The original idea was to create protection against DDoS attacks and spam.
Read 18 tweets
17 Feb
What are **some** possible applications of Blockchain technology?

Are there only cryptocurrencies? Are there more possible applications? Let's take a look at three possible applications outside of finance here to give you a general idea of what is possible.

🧵🔽
0️⃣ Foreword

A blockchain can be used to solve a lot of problems. Cryptocurrencies are only one possible way of applying the technology but there is way more to it.

We can take a look at some possible applications and what they each provide to users.
1️⃣ Social Networks

The current generation of social networks is centralized. Whether we talk about Facebook, Twitter, Instagram, TikTok, or whatever else. They all own your account, your content, your followers, and everything else.
Read 19 tweets
16 Feb
What actually is a Blockchain?

Bitcoin is breaking record after record, but there must be more to the technology than just crypto, or not? Well, we can take a look at the underlying technology first to understand what it actually provides to us.

🧵⬇️
1️⃣ Foreword

This will be a high-level overview to give you an intro to blockchain technology. With further threads, we will dive deeper and deeper, so don't be sad if something you really looked forward to isn't included as detailed as you would have wished for, yet!
2️⃣ Client-Server Architecture

Before we dive into blockchain technology, we should take a look at how most of the internet works. We need this to understand the fundamental differences between a traditional model and the change blockchain technology brings.
Read 29 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!