开发者

What design pattern is this?

I have an interface declaring 4 methods ... I added an abstract class implementing this interface to give developers the opportunity to choose how many methods they want to imple开发者_如何学编程ment (specially useful in case of a listener) ...

public interface Mylistener {
    void actionA();
    void actionB();
    void actionC();
    void actionD();
}
public abstract class MylistenerWrapper implements Mylistener {
    public void actionA(){}
    public void actionB(){}
    public void actionC(){}
    public void actionD(){}
}

and now developers are not obliged to implement all the interface methods :

Mylistener l1 = new MylistenerWrapper(){
    public void actionA(){
    //treatment for actionA
    }
    public void actionD(){
    //treatment for actionD
    }
}    
Mylistener l2 = new MylistenerWrapper(){
    public void actionC(){
    //treatment for actionC
    }
}

My question : what design pattern is this ? I already named my class wrapper (adapter) is it ok ?


Adapter probably (by analogy with different EventListenerAdapters in Swing).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜