πŸ’‘ What is an Interface?

An interface in TypeScript is used to define the structure or blueprint of an object or a class.

It only defines what properties and methods should exist, but not how they work.

Think of it as a rule book β€” if a class agrees to follow it, it must define everything that the interface declares.

βœ… Example:

interface Animal {
  name: string;
  makeSound(): void;
}

class Dog implements Animal {
  name = "Tommy";

  makeSound() {
    console.log("Woof! 🐢");
  }
}

const dog = new Dog();
dog.makeSound(); // Woof! 🐢

πŸ“ Explanation:

So basically,

πŸ‘‰ Interface = "Yeh sab cheeze honi chahiye",

but "kaise hongi" β€” that’s up to the class.


βš™οΈ What is an Abstract Class?

An abstract class is like a half-built blueprint β€” it can have some real methods (with code) and some abstract methods (without code).

You can’t directly create an object from an abstract class.

You must create a subclass that extends it and implements the abstract methods.

βœ… Example:

abstract class Animal {
  constructor(public name: string) {}

  // Abstract method β€” no body, must be defined by subclass
  abstract makeSound(): void;

  // Concrete method β€” real logic
  move() {
    ****console.log(`${this.name} is moving...`);
  }
}

class Dog extends Animal {
  makeSound() {
    console.log("Woof! 🐢");
  }
}

const dog = new Dog("Buddy");
dog.move();       // Buddy is moving...
dog.makeSound();  // Woof! 🐢