Re: package private problem
"John Esquel" <john_esquel@remove.also.this.wp.pl> wrote in message
news:eetqv9$sq0$1@atlantis.news.tpi.pl...
Thank you very much for reply.
Please, see my comments below.
"Thomas Weidenfeller" <nobody@ericsson.invalid> wrote in message
news:eetpdm$oo5$1@news.al.sw.ericsson.se...
John Esquel wrote:
I have a small package design problem, I wonder if it can be solved
somehow.
I have 2 classes (with package private access) in 1 "mypackage" package:
package mypackage;
class MyClass {
private MyClassItem _item;
Consider dropping that leading underscore '_' prefix. That's a C++
convention (and a rather ugly one), typically avoided in Java.
IMHO '_' prefix in front of class fields is one of the best coding
standards
(it is a coding standard in my complany - 200+ developers).
When you have dozens of lines in dozens of methods in a class,
you see on the spot which variable is a local one and which is the class
field.
Thomas, you have any other method for such distinction ?
Eclipse shows fields in blue and local variables in black.
IMHO '_' might be more useful to say which fields are public and which
are not. The default configuration of Eclipse displays all fields the same
way, though probably there's a way to configure it to display public fields
in dark blue, and private fields in light blue, for example.
All that said, it's probably more important to stick to the coding
standards in your project, and to use the "best" coding standards in the
world.
Now I want to add subpackage mypackage.items
and move MyClassItem there (I need a new subpackage as I will have many
different item classes there).
There is no such thing as a subpackage in Java. Package a.b and a.b.c are
logically not more related than package a.b and x.y. That is, they are
entirely different packages and there are no special logical "subpackage"
rules, visibility or relations in Java.
[When logical package names are mapped to physical directories you have a
subdirectory relationship, but that has no influence on the logical
relation].
Your packages are entirely different package, and the normal visibility
rules apply.
Thanks, that makes sense.
I know that, when designing in mid-90ties, Java was planned to be as
simple as possible,
but in 1.5 it is no longet such,
and imho it would be good idea for java designers to improve class access
priviledges (subpackages of friendly classes)
What do you think Thomas ?
Well, first they'd have to invent or define the concept of a
"subpackage". If it's merely that "a.b.c" is a subpackage of "a.b", and the
existence of subpackages can change the behaviour of code, you'll end up
with a huge backwards compatibility issue.
- Oliver