Junior — Middle
Why is it important to declare base methods in an interface when designing a system?
sobes.tech AI
Answer from AI
Declaring basic methods in an interface during system design is important for ensuring contract-based programming and architectural flexibility. This allows:
- Defining a clear set of mandatory operations that must be implemented by all classes implementing the interface.
- Ensuring polymorphism, enabling work with different implementations through a common interface.
- Simplifying testing and component replacement without changing client code.
- Improving code readability and maintainability, as the interface serves as documentation for functionality.
For example, in Android, you can declare a Repository interface with basic methods getData() and saveData(), so that different implementations (such as local database or remote server) have the same contract.