Reputation: 5440
I know why use interface and wrapper.
But I confuse to name wrapper class... ("Who is wrapper?" I see I do not know well...)
public Interface A {
void method();
}
public Class B implements A {
void method() {
doSomething();
}
}
I am confused by two things...
Wrapper Class is class , so B is wrapper.
We usually see(or think?) a.method() not b.method(), so A is wrapper.
What is wrapper?
A? B?
And...
How to name A,B good using "Wrapper" or "W"?
A, AWrapper? or B, BWrapper? or others...?
Upvotes: 1
Views: 10285
Reputation: 4389
Neither A or B from your example can be called a wrapper. The relationship between A and B is Inheritance
. A Wrapper
class usually contains
one or more Wrappee
objects. Adapter and Facade patterns are good examples of wrappers.
See this for a detailed discussion on Wrappers
Upvotes: 3
Reputation: 28029
A
is an interface. B
is a concrete implementation of Interface
. Nothing else can be said about them from the code you provided.
A Wrapper "wraps" the functionality of another class or API by adding or simplifying the functionality of the wrapped class/API. For example, the Primitive Wrappers from Java add useful methods like doubleValue
and compareTo
to Java primitives.
You're thinking of Polymorphism.
That's what allows us to say things like:
A a = new B();
B b = new B();
List<A> stuffs = new ArrayList<A>();
stuffs.add(b);
Side note:
Interface
and Class
are not allowed to be capitalize in Java. Your declarations should be like so:
public interface A {
// methods
}
public class B implements A {
// methods
}
Upvotes: 5