Jebel <Jebel.S...@gmail.com> wrote:
I not understand how to do this. How can I "wrap" B's methods ?
Would you please provide some code as a example?
It was based on a wrong understanding on my side. Sorry, but
I think it doesn't apply, anyway.
The point was about your class in xx.zz.gg which you could
give a such limited interface, that noone could do anything
harmful with it, even if the wrong "user" tries...
The wrapping was just meant as a way to restrict the interface:
e.g.:
package xx.zz.gg;
class B {
// lots of public methods, some of which are potentially dangerous
public void foo() { ... }
public void bar() { ... }
public void snafu() { ... }
...}
and:
package xx.zz.gg;
class BWrapper {
B wrappedB;
BWrapper(B b) { wrappedB=b; }
private B getB() { return wrappedB; }
// just the really important methods:
public void foo() { do some checks, and then: getB().foo(); }}
After that, you can give all the methods of B default-access,
and no one else can use anything than foo() on B, and only through
your class BWrapper (unless they find a way to sneak code into
xx.zz or xx.zz.gg bypassing your classloader, or patching their
JVM).
Also, I don't yet understand what big evil would be unleashed by
letting people just use your xx.zz.gg.B as they feel like.
the ' wrap ' . :-)