Interface Segregation Principle

What is the Interface Segregation Principle?

Let us understand the Interface Segregation Principle with an example.

interface Bird {    public void putEggs();
public void peck();
public void fly();
public void land();
}
class Falcon implements Bird
{
public void putEggs() { // it can put Eggs }
public void peck() { // it can peck }
public void fly() { // it can fly }
public void land() { // it can land }
}
class Penguins implements Bird {

public void fly() { //throws Exception; }
// Above method will not work because Penguins can not fly, but //still we need to handle this method
}
interface Bird
{
public void putEggs();
public void peck();
}

interface Flying
{
public void fly();
public void land();
}

class Penguin implements Bird
{
//...
}

class Chicken implements Bird
{
//...
}

class Falcon implements Bird, Flying
{
//...
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store