Imagine you are developing a multi-module application where some modules will be developed by third-party vendors. How would you ensure that the third-party modules adhere to a certain API but do not inherit default method implementations?

  • Provide a detailed API documentation to third-party vendors, leaving it to them to ensure API adherence without enforcing a specific coding approach.
  • Use a combination of interfaces and abstract classes, allowing third-party vendors to choose between them based on their needs.
  • Use abstract classes for the API, providing method stubs without default implementations, and have third-party vendors extend these classes to implement the API.
  • Use interfaces with default methods for the API, allowing third-party vendors to implement the interface while overriding the default methods as needed.
In this scenario, using abstract classes for the API is the preferred choice. Abstract classes provide method stubs without default implementations, ensuring that third-party vendors must implement the required methods while giving them flexibility in their approach. Interfaces with default methods could lead to unwanted method inheritance.
Add your answer
Loading...

Leave a comment

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