Given:
public class Main { private D d;/*from ww w. j a v a 2s . com*/ public void m() { d.m(); } public static Main getInstance() { return new Main(); } } class D { public void m() {} }
Which design pattern or principle is implemented?
D is correct.
The object composition principle of method forwarding is shown.
Option E is tricky, but incorrect.
Although getInstance()
is a common name for a method in a singleton, the method doesn't return a static object.
While it does create an object, it isn't a factory either, since there is no superclass.