Should each class have an interface?

Source: Internet
Author: User
In the SOILD principle, almost all OILD requires interface intervention. Do I need to provide an interface for every class during development? Is this language-specific? When I use a multi-layer architecture for SSH, it is natural that I will build a service, service-impl, dao, dao-impl. However, you are developing A client or...
  1. SOILDIn principleOILDAlmost all require interface intervention. Do I need to provide an interface for every class during development?
  2. Is this language-specific? I'm doingSSHIt is natural to choose a multi-layer architecture.service,service-impl,dao,dao-impl. However, you are developing a client orASP.NET MVCIs it because of technical capability issues. InphpIt seems that there are very few objects to be connected. Is this related to language?
  3. Is it necessary to adopt the "open and closed principle" in the early stage of development? Will there be more interfaces, making the code hard to read?

Reply content:
  1. SOILDIn principleOILDAlmost all require interface intervention. Do I need to provide an interface for every class during development?
  2. Is this language-specific? I'm doingSSHIt is natural to choose a multi-layer architecture.service,service-impl,dao,dao-impl. However, you are developing a client orASP.NET MVCIs it because of technical capability issues. InphpIt seems that there are very few objects to be connected. Is this related to language?
  3. Is it necessary to adopt the "open and closed principle" in the early stage of development? Will there be more interfaces, making the code hard to read?

My suggestion is: refer to the three rules

For the first time, you don't have to worry about principles, suggestions, and so on.
The second time, I was alert when I began to repeat, but I was able to tolerate some violations of principles.
Repeat your code for the third time

Of course, if you have foreseen that the problem will come three times when you solve the problem for the first time, it is okay to write it in the third way. But if you predict that the problem will never come true, don't design so many things. Follow YAGNI.

References: refactoring book/YAGNI principles/DRY principles/premature optimization
SOLID vs YAGNI on stackoverflow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.