java - Deregister delegated class -
i have decided use composition extend functionality of several service classes have in project adding security layer prevent calling method. fine until found class registers listener service , see i'll need extend method called in listener. listener registered in init method of class thought 'de-register' delegated class after init method has been called , register instead composited class feel it's bit dirty... know think approach or how solve this.
maybe can have better idea looking @ example of classes have:
public abstract class serviceabs { protected void init(); } public interface oldclassif { public void amethod(); } public myoldclass extends serviceabs implements oldclassif, listenerif { protected void init() { observer.addlistener(this); //other stuff needed } public void onlistener() { } @override public void amethod() { } } public mynewclass extends serviceabs implements oldclassif, listenerif { myoldclass oldclass; public void onlistener() { if(condition) { oldclass.onlistener(); } } protected void init() { oldclass.init(); observer.removelistener(oldclass); observer.addlistener(this); } public void amethod() { if(condition) { oldclass.amethod(); } } }
Comments
Post a Comment