What does program to interfaces, not implementations mean?
What does program to interfaces, not implementations mean?
The principle "program to interfaces, not implementations" is a fundamental concept in software design, particularly in object-oriented programming. It advises developers to depend on abstractions (interfaces or abstract classes) rather than concrete classes. This approach enhances the flexibility and extensibility of code, making it easier to modify or extend without altering existing code.
Abstraction Over Implementation:
Decoupling:
Flexibility and Maintainability:
Example in Practice:
Sorter
interface with a sort
method, different sorting algorithms like QuickSort or MergeSort can be implemented by classes that implement this Sorter
interface. The client code remains unchanged and can operate with any object that conforms to the Sorter
interface, thus adhering t...middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào