• <tfoot id='PXKo7'></tfoot>

    <i id='PXKo7'><tr id='PXKo7'><dt id='PXKo7'><q id='PXKo7'><span id='PXKo7'><b id='PXKo7'><form id='PXKo7'><ins id='PXKo7'></ins><ul id='PXKo7'></ul><sub id='PXKo7'></sub></form><legend id='PXKo7'></legend><bdo id='PXKo7'><pre id='PXKo7'><center id='PXKo7'></center></pre></bdo></b><th id='PXKo7'></th></span></q></dt></tr></i><div id='PXKo7'><tfoot id='PXKo7'></tfoot><dl id='PXKo7'><fieldset id='PXKo7'></fieldset></dl></div>

        <legend id='PXKo7'><style id='PXKo7'><dir id='PXKo7'><q id='PXKo7'></q></dir></style></legend>

        <small id='PXKo7'></small><noframes id='PXKo7'>

          <bdo id='PXKo7'></bdo><ul id='PXKo7'></ul>

        接口应该放在单独的包中吗?

        时间:2023-09-27

            <bdo id='SHLP2'></bdo><ul id='SHLP2'></ul>
            <tfoot id='SHLP2'></tfoot>

            • <small id='SHLP2'></small><noframes id='SHLP2'>

                <legend id='SHLP2'><style id='SHLP2'><dir id='SHLP2'><q id='SHLP2'></q></dir></style></legend>
                  <tbody id='SHLP2'></tbody>

                  <i id='SHLP2'><tr id='SHLP2'><dt id='SHLP2'><q id='SHLP2'><span id='SHLP2'><b id='SHLP2'><form id='SHLP2'><ins id='SHLP2'></ins><ul id='SHLP2'></ul><sub id='SHLP2'></sub></form><legend id='SHLP2'></legend><bdo id='SHLP2'><pre id='SHLP2'><center id='SHLP2'></center></pre></bdo></b><th id='SHLP2'></th></span></q></dt></tr></i><div id='SHLP2'><tfoot id='SHLP2'></tfoot><dl id='SHLP2'><fieldset id='SHLP2'></fieldset></dl></div>
                1. 本文介绍了接口应该放在单独的包中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我是一个团队的新手,该团队正在处理一个相当大的项目,其中包含许多组件和依赖项.对于每个组件,都有一个 interfaces 包,用于放置该组件的公开接口.这是一个好习惯吗?

                  I'm new to a team working on a rather large project, with lots of components and dependencies. For every component, there's an interfaces package where the exposed interfaces for that component are placed. Is this a good practice?

                  我通常的做法是接口和实现放在同一个包中.

                  My usual practice has always been interfaces and implementations go in the same package.

                  推荐答案

                  把接口和实现都放在一个普通的地方,好像没有问题.

                  Placing both the interface and the implementation is common place, and doesn't seem to be a problem.

                  以 Java API 为例——大多数类的接口及其实现都包含在同一个包中.

                  Take for example the Java API -- most classes have both interfaces and their implementations included in the same package.

                  java 为例.util 包:

                  它包含SetMapList等接口,同时也有HashSet、HashMapArrayList.

                  It contains the interfaces such as Set, Map, List, while also having the implementations such as HashSet, HashMap and ArrayList.

                  此外,Javadocs 旨在在这些条件下正常工作,因为它在显示包的内容时将文档分为 InterfacesClasses 视图.

                  Furthermore, the Javadocs are designed to work well in those conditions, as it separates the documentation into the Interfaces and Classes views when displaying the contents of the package.

                  只为接口提供包实际上可能有点过分,除非有大量的接口.但是仅仅为了这样做而将接口分离到自己的包中听起来是不好的做法.

                  Having packages only for interfaces may actually be a little bit excessive, unless there are enormous numbers of interfaces. But separating the interfaces into their own packages just for the sake of doing so sounds like bad practice.

                  如果需要将接口的名称与实现区分开来,可以有一个命名约定以使接口更易于识别:

                  If differentiating the name of a interface from an implementation is necessary, one could have a naming convention to make interfaces easier to identify:

                  • 在接口名称前加上 I. 这种方法适用于 .NET 框架中的接口.很容易看出 IList 是一个列表的接口.

                  • Prefix the interface name with an I. This approach is taken with the interfaces in the .NET framework. It would be fairly easy to tell that IList is an interface for a list.

                  使用-able后缀.这种方式在Java API中经常看到,如<​​code>ComparableIterableSerializable 等等.

                  Use the -able suffix. This approach is seen often in the Java API, such as Comparable, Iterable, and Serializable to name a few.

                  这篇关于接口应该放在单独的包中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:struts.xml 中 Struts 的默认包名是什么? 下一篇:为什么我能够重新创建 java.lang 包和类?

                  相关文章

                  最新文章

                  1. <tfoot id='RzIOI'></tfoot>
                  2. <i id='RzIOI'><tr id='RzIOI'><dt id='RzIOI'><q id='RzIOI'><span id='RzIOI'><b id='RzIOI'><form id='RzIOI'><ins id='RzIOI'></ins><ul id='RzIOI'></ul><sub id='RzIOI'></sub></form><legend id='RzIOI'></legend><bdo id='RzIOI'><pre id='RzIOI'><center id='RzIOI'></center></pre></bdo></b><th id='RzIOI'></th></span></q></dt></tr></i><div id='RzIOI'><tfoot id='RzIOI'></tfoot><dl id='RzIOI'><fieldset id='RzIOI'></fieldset></dl></div>
                        <bdo id='RzIOI'></bdo><ul id='RzIOI'></ul>

                    1. <legend id='RzIOI'><style id='RzIOI'><dir id='RzIOI'><q id='RzIOI'></q></dir></style></legend>

                    2. <small id='RzIOI'></small><noframes id='RzIOI'>