DEV Community

Cover image for Interface segregation principle (SOLID)
pedchenkoroman
pedchenkoroman

Posted on • Edited on

Interface segregation principle (SOLID)

Motivation

Hi guys. My name is Roman Pedchenko and I am a full-stack developer. Pleased to make your acquaintance. It is my first article and I ask you do not judge it too harshly. The idea to write the article appeared after my conversation with my friend Max Grom and I want to say thanks him.

Story

There are lot's of developers has an technical interview every day. Someone wants to receive a new job, someone the first one. But the problem is that you have to show your knowledge in a limited period of time which is why every answer is really important. In my humble opinion there are three types of answers. The first one is just academic knowledge. It means that you read about something but do not use it. The second one is you can describe or give an example from real world but you could not answer on the questioin what is it a principal or paradigm or pattern. And last but not least it is to combine the first and the second. Not only you know how to use it but also what you use. As you probably guess that the third
one amplifyes your position on an interview as a really good developer.

I bet everyone it does not metter you are a candidate or an interviever to prepare for the interview repeats SOLID principals. In addition to that I beleive that everyone tryes to use it every day but when someone asks could you explain them and gives some examples. It is always so dificult. In this article I will touch only one letter from abreviation but I hope it helps you to be more convincied.

Letter I

If you open wiki you will easily figure out that

The interface segregation principle (ISP) states no code should be forced to depend on methods it does not use.ISP splits interfaces that are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them.

I hope it sounds really easy to understand but as I wrote above not only teoretical knowled but also the examples where do we use it and here there are lots of people to get stuck. And here's a hint. It is easier than learning the definition itself. If you are a Angular developer that you are lucky person. Every time and every day when you create a component and add some hooks to component you use it.

export class AppComponent implements OnInit, OnDestroy {
  ngOnInit() {
  // some logic
  }

  ngOnDestroy() {
  // some logic
  }
}
Enter fullscreen mode Exit fullscreen mode

As you can see we have to implement two interfaces in order to that hooks start to work and that's all. And oddly enough I believe that this answer will show you that at least you know the letter I from SOLID.

Thank you and break a leg at a job interview.

Top comments (0)