I'm new to design pattern subject area and keen to understand the implementation variations of design patterns. I have seen the following structure for adapter class in adapter design pattern in numerous tutorials on web. (Following code sample is extracted from wikipedia )
public class ClassAFormat1 implements StringProvider {
private ClassA classA = null;
public ClassAFormat1(final ClassA A) {
classA = A;
}
public String getStringData() {
return format(classA.toString());
}
}
If i'm not mistaken, ClassA is the adaptee and StringProvider is the target in this example (Classes are not provided here).
I have made a small adjustment to the above code by defining and initializing the adaptee class within the method of target. I know its strange but want to know whether it still belongs to the adapter design pattern.
public class ClassAFormat1 implements StringProvider {
public String getStringData() {
ClassA classA = new ClassA();
return format(classA.toString());
}
}
Has the above adapter class written according to the guidelines of adapter design pattern?
Thank you.