An abstract class is a base class from which other classes can be derived. An abstract class serves as a foundational blueprint for creating more concrete classes.
Abstract classes cannot be instantiated directly.
They can implement methods of their own.
They can define methods that inheriting classes must implement.
They are primarily used for inheritance, allowing other classes to extend from them.
Abstract methods or properties: Abstract classes typically include one or more abstract methods or property declarations.
Inheritance: Other classes derive from abstract classes to share common functionality.
No direct instantiation: You cannot create an instance of an abstract class directly.
A property name.
A normal method display().
An abstract method find(name: string): Person.
Employee derives from Person.
Employee must implement the find() method defined in Person.
The abstract class enforces a contract that derived classes must fulfill.
When implementing an abstract class, the derived class must call super() in its constructor.
Abstract classes can also include abstract properties.
Remember, abstract classes provide a powerful way to structure and share functionality while ensuring adherence to a specific contract.
We have a simple Shape interface with an area() method. How would you refactor it into an abstract class so that Circle and Rectangle can share a common color property and a default toString() implementation?
If you declare an abstract class Vehicle with an abstract startEngine() method, what error do you get when a subclass forgets to implement startEngine, and how would you fix it?
Can you try to instantiate an abstract class directly in TypeScript? What compile‑time error appears, and why?
Our codebase defines an abstract BaseApiService that provides a protected httpClient. A new service extending it crashes at runtime with Cannot read property 'get' of undefined. Walk me through how you'd debug this issue.
We're deciding between an abstract class and an interface for a plugin system that needs shared helper methods. What factors would guide your choice?
During a refactor a developer changed a concrete method in an abstract class to abstract, causing compile errors in several subclasses. How would you resolve the breakage while keeping the change minimal?
Our microservice framework uses an abstract RequestHandler with a synchronous handle() method. We now need to support async handlers without breaking existing subclasses. How would you evolve the abstract class design?
A large UI component hierarchy extends an abstract Component class. Adding a new lifecycle hook caused noticeable performance regressions. How would you evaluate the impact and decide whether to keep the hook?
When abstract classes are exported from separate npm packages, we sometimes see instanceof checks fail because of duplicate type definitions. Explain why this happens and how to prevent it.
Our legacy JavaScript code uses function constructors to mimic inheritance. We're migrating to TypeScript and want to replace them with abstract classes while preserving backward compatibility. Outline a migration plan.
We need a contract for all data‑access objects across multiple services. Would you choose an abstract class, an interface, or a hybrid approach? Discuss the long‑term maintenance and versioning implications.
A cross‑team initiative is releasing a public SDK that relies on abstract classes for extensibility. What versioning strategy and compatibility guarantees would you put in place to avoid breaking downstream consumers?