Language/Java 2009.11.16 00:24
Java has useful visibility; package private.
Let's see the following case.
We want implement quite big module A. And this has some sub features. So, we need to make sub classes a, b, c.
In this case, external module should be able to see only interfaces of A; Not those of a, b and c. It is very difficult to make this in C++. But, in java, we can use package private. Here is design example.
Put all these modules in the same package.
Make interfaces of A as public.
Make all interfaces of a, b and c be package private.
Developer can easily know that using a, b and c directly is not allowed intuitively.
How about in C++?
In C++, there is no proper way to do this. Making A be 'friend' of a, b and c, breaks encapsulation. Making interfaces of a, b and c be public, may lead to misuse of those; we want only interfaces of A be visible to external.
I has been desired this kind of visibility - ex. namespace private - when using C++. :-)
|[Java][Test Code] ThreadPoolExecutor... (0)||2013.09.25|
|[Java] Visibility에서 추가했으면 하는 것.... (0)||2011.04.21|
|[Java] Some notable stuffs of VM (0)||2011.01.06|
|[Java] Simple sample codes to remind... (0)||2010.12.07|
|[Java] Package private in Java (0)||2009.11.16|
|[Java][Tips] Compile... (0)||2009.10.18|