Why we need an interface ?

Why we need an interface ?

Consider the following situation:

You are walking in the park and suddenly some wild animal attacks you

You have no weapon.

Luckily, you see a person nearby

"Quick!" you shout at him. "Throw me something I can hit the animal with!"

Now consider:
You didn't specify (nor do you care) exactly what your friend will choose to toss;
...But it doesn't matter, as long as:

  • It's something that can be tossed (He can't toss you a vehicle)

  • It's something that carries some weight (Let's hope he doesn't toss a piece of cloth)

  • It's something you can kill an animal

It doesn't matter whether you get a baseball bat or a hammer -
as long as it implements your three conditions, you're good.

To sum it up:

When you write an interface, you're basically saying: "I need something that..."

Rajesh Gour

Cloud Migration Consultant | .Net Core| C# | .Net | ReactJS | Angular | Full Stack Developer | Azure | PCF | POWER BI | H1B

9 年

Awesome Soheb !!

要查看或添加评论,请登录

Shoeb Sayyed的更多文章

社区洞察

其他会员也浏览了