You are developing a system where you have multiple classes, and you want to ensure that a particular set of methods is available in all these classes. How would you ensure this?

  • Inherit a base class with the common methods
  • Use composition and create a separate class for the common methods
  • Use global functions for the common methods
  • Use interfaces to define the required methods
In JavaScript, you can't directly inherit from classes, but you can use interfaces to ensure a set of methods is available in implementing classes. Interfaces define method signatures that must be implemented by the classes that use them.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *