What if you could control many different things with just one simple command?
Why Polymorphism through interfaces in Typescript? - Purpose & Use Cases
Imagine you have different types of devices like a phone, a tablet, and a laptop. You want to turn them all on, but each device has its own way to do it. Without a common plan, you have to write separate code for each device every time.
Writing separate code for each device is slow and confusing. If you add a new device, you must change many parts of your program. This makes mistakes easy and your code hard to manage.
Using interfaces, you create a shared plan that all devices follow. This way, you can treat all devices the same way in your code, even if they work differently inside. It keeps your code clean and easy to grow.
phone.turnOn(); tablet.powerUp(); laptop.start();
device.turnOn(); // device can be phone, tablet, or laptopIt lets you write flexible code that works with many different things without changing your main program.
Think of a music app that plays songs from different sources: local files, streaming services, or radio. Using interfaces, the app can play any source without knowing the details.
Interfaces create a common plan for different objects.
Polymorphism lets you use different objects in the same way.
This makes your code easier to write, read, and extend.