My question is simple: is there any advantage of using interfaces if they are implemented by a single class ?
I always thought that interfaces are good only when there are multiple implementations of that interface.
Thanks.
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.
In a word: no. The contract that an interface means can be specified directly in your only class.
If you are clear that you won’t need another implementation of the same methods in the future, you can avoid defining an interface.
Of course, the issue here is “in the future” clause. If the project is small, without a long development/upgrade period, and well defined, you can be almost sure about what will be needed in the future.
If the project is long as is probably that it will be subjected to changes, then you will have to factor in: