Saturday 15 May 2010

eclipse - Java package organization and access modifier -


So I am struggling with the organization of my classrooms and packages. I have many classes, so I am currently sorting them with related packages. Now I have the following condition with 2 sections:

with a 'not public' manufacturer:

  package example; Public class file {file () {// constructor should not be public} // stuff ...}  

and creator using another person:

 < Code> Package example.specialfiles; Import example.file; Public Category CatalogFile {Private file wrapped file; List file () {wrappedFile = new file (); } // stuff ...}  

which looks like eclipse.

Obviously the file-constructor can not be called within the catalog file, because it is located in the second package.

Since there is no C # internal internal is the only one working solution that I can think is that they have been put in the same package, which in my opinion Breaks the purpose of the package.

If you do not want others to instantiate their files (better If you want to hide your constructor from others, you can get a getInstance (). ) Method that creates your object (factory method pattern) for you, and in the method you can see whether the caller is created or not In the access to, for example with the Java Reflection API.


No comments:

Post a Comment