扩展类时应该保留包名称吗?

发布于 2024-08-12 00:39:18 字数 313 浏览 3 评论 0原文

我计划扩展一个 JSF 渲染器。包名称为 oracle.adfinternal.view.faces.renderkit.rich

扩展类是否应位于相同的包结构中: oracle.adfinternal.view.faces.renderkit.rich 甚至是 oracle.adfinternal.view.faces.renderkit.rich.[subpackage]

或者我可以/应该将它放入我自己的包中吗? com.company.renderkits。

我想如果我将其放入我自己的包名称中,包私有变量可能会受到干扰?

有什么想法吗?

I plan to extend a JSF renderer. The package name is oracle.adfinternal.view.faces.renderkit.rich

Should the extended class be in the same package structure:
oracle.adfinternal.view.faces.renderkit.rich
or even oracle.adfinternal.view.faces.renderkit.rich.[subpackage]

or can/should I put it into my own package? com.company.renderkits.

I suppose package-private variables might be interfered with if I put this into my own package name?

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

最佳男配角 2024-08-19 00:39:18

一般来说,您应该将扩展类放在您自己的包中。

包私有访问级别应该由紧密相连的类使用,这些类可能是由了解所有实现细节的同一开发人员编写的。如果您扩展具有某些功能的类,则情况并非如此。

尽管如此,在某些情况下,您需要将类放在超类的包中作为解决方法,但请记住,这是一个丑陋的黑客行为,并尽力避免它。

In general, you should put your extended classes in your own package.

The package-private access level should be used by closely connected classes, possibly written by the same developer, who knows all the implementation details. This is not the case if you extend a class with some functionality.

All that said, there are a few occasions where you need to place your class in the package of the superclass as a workaround, but remember, this is an ugly hack, and try hard to avoid it.

忘羡 2024-08-19 00:39:18

您应该将该类放入您自己的包中。不应该有任何编译/访问问题。超类已经看到了它需要看到的内容。

You should put the class into your own package. There shouldn't be any compilation/access problems. The superclass already sees what it needs to see.

凹づ凸ル 2024-08-19 00:39:18

我想如果我将其放入我自己的包名称中,包私有变量可能会受到干扰?

这是事实,但通常扩展类不应该担心这一点。否则,要扩展的类将使用 protected 修饰符。

I suppose package-private variables might be interfered with if I put this into my own package name?

This is true, but normally the extending class shouldn't worry about this. The to-be-extended class would have used the protected modifier for this otherwise.

一花一树开 2024-08-19 00:39:18

您不应该将东西添加到其他实体(公司、个人)包中。他们可以在以后创建一个具有相同名称(当然还有相同包)的类。他们还可以选择将其 JAR 文件密封为好吧,这会阻止您将类添加到他们的包中。

包的目的是为每个实体提供自己独特的命名空间,以便在其中创建类型。

在您的情况下,我会将包命名为: com.foobar.oracle.adfinternal.view.faces.renderkit.rich 其中“com.foobar”是您实体的反向域名(如果您没有选择某个名称)这是独一无二的)。

You should not add things to other entities (companies, person) packages. They could make a class with the same name (and same package of course) at a later date. They could also choose to seal their JAR files as well which would prevent you from adding classes to their packages.

The purpose of packages is to give each entity their own unique namepsace in which to create types.

In your case I would name the package something like: com.foobar.oracle.adfinternal.view.faces.renderkit.rich where "com.foobar" is the reverse domain name of your entity (if you don't have one pick something that is unique).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文