I have confusion with polymorphism (same scheme as CGLIB proxy). I have two classes:
- ParentService -> looks like target object
- ChildService -> looks like a proxy object
public class ParentService {
public void method1() {
System.out.println("ParentService.method1()");
}
public void method2() {
System.out.println("ParentService.method2()");
}
public void callBoth() {
System.out.println("ParentService.callBoth()");
method1();
method2();
}
}
and
public class ChildService extends ParentService {
private final ParentService parentService;
public ChildService(ParentService parentService) {
this.parentService = parentService;
}
@Override
public void method1() {
System.out.println("ChildService.method1()");
parentService.method1();
}
@Override
public void method2() {
System.out.println("ChildService.method2()");
parentService.method2();
}
public void callBoth() {
System.out.println("ChildService.callBoth()");
parentService.callBoth();
}
}
Output:
ChildService.callBoth()
ParentService.callBoth()
ParentService.method1()
ParentService.method2()
Why in this case we don't call ChildService implementation? Please, don't mark this question unuseful, I really wasn't able to found the answer. Thank you for your patience.