English 中文(简体)
Should I keep the package name when extending a class?
原标题:

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?

最佳回答

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.

问题回答

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.

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.

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).





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签