Useless interfaces

后端 未结 25 1631
南笙
南笙 2020-12-14 01:42

Why would you ever use an interface if you are only going to have one implementation of it?

25条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 02:24

    If you are working with a system that allows refactoring, you should only add interfaces if either it is needed for the specification (say, an external API) or if you need multiple implementations. I consider test objects to be valid interpretations, so if you need an interface in order to get it under test, that is a fine use of interfaces.

    Value objects should rarely become interfaces, service objects should frequently become interfaces.

提交回复
热议问题