Such processing schemes are no longer customary to do.
The first version is absolutely terrible, the second one is just bad.
For event handling, there is a fairly common pattern. It is customary to make an interface to the event listener.
public interface MyControlListener { void onDataChanged(int dataAddedCount); }
The control itself should have a list of handlers:
public class MyControl /*...*/ { private ArrayList<MyControlListener> listeners = new ArrayList<MyControlListener>(); public void addListener(MyControlListener listener) { listeners.add(listener); } public void removeListener(MyControlListener listener) { listeners.remove(listener); } private void fireListeners(int count) { for(MyControlListener listener : listeners) { listener.onDataChanged(count); } } /* ...... код может вызывать fireListeners(count) когда требуется уведомить слушателей */ }
After that, everyone who is interested in this event can subscribe to the event, for example, like this:
class MyController implements MyControlListener { public void myInitMethod() { MyControl ctl = new MyControl(); ctl.addListener(this); } @Override public void onDataChanged(int count) { // тра-ла-ла } }
This is a common best practice and is used almost everywhere. Look, at least, at what is already there, at how existing events are made.