In the Head First Design Patterns book, the author often says that one should program to interface rather than implementation?
What does that mean?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Let’s illustrate it with the following code:
Suppose you are the
Loggerdeveloper and the application developer needs aLoggerfrom you. You give the Application developer yourILoggerinterface and you say to him he can use but he doesn’t have to worry about the implementation details.After that you start developing a
FileLoggerandDatabaseloggerand you make sure they follow the interface that you gave to the Application developer.The Application developer is now developing against an interface, not an implementation. He doesn’t know or care how the class is implemented. He only knows the interface. This promotes less coupling in code and it gives you the ability to (trough configuration files for example) easily switch to another implementation.