Note that there are some explanatory texts on larger screens.

plurals
  1. POJava/Patterns for hiding methods from third party classes
    text
    copied!<p>I have a class A that has a series of handlers e.g. public void handleEv1(),public void handleEv2() etc. When an event occurs, another thread in class B, calls the correspondent handler from class A (class B has a reference to class A kind of observer-observable). In the handling of the event in the corresponding method of class A, A eventually raises an event to an eventListener (class C which is not created by me). My question is the following: is there a pattern I can use to "hide" the handling methods of class A from the classes that act as eventListeners (not implemented by me), and be "visible/accesible" only to class B (which I implement)?</p> <p>I am editing my original question. I have class Csystem that has a lot of methods and the handlers I am talking about</p> <pre><code>public class Csystem() { private AListener listener;//implements an event listener (the class C in my question) //some methods here public void handleEventIncoming(Event e){ //Do some logic here listener.raiseEvent(e); } public void handleEventOutgoing(Event e); etc } </code></pre> <p>CSystem is a class that is essentially an interface for other developers of other components to my code. Some other developer will write his own version of class AListener (class A) and use Csystem in his code. Whenever an event occurs somewhere (e.g. a message in the network arrived) class B will pass the event to the event handlers of CSystem</p> <pre><code>public class Dispatch{ //This is class B private CSystem s; private void event_occured(Event e) { s.handleEventIncoming(e); } } </code></pre> <p>} My problem is that both class Dispatch (implemented by me) and class AListener "see" the same interface of CSystem. I would like the developers who implement the AListener to see a different view of CSystem and "see" and be able to use only methods that are public. I don't think that it is a good idea to see methods someone actually can not use (handlers are meaningful to be used only by dispatcher) Is there a pattern to achieve this?</p> <p>Thank you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload