Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing one object to many classes using Java

Tags:

java

listener

I need to pass an object from one class to many different classes.

The aim of this is to create one method that broadcasts the object to any other classes that are listening. This is so that more classes can be added and I just need to implement a listener function for that class and not edit any of the framework.

I am trying to accomplish this without the use of JMS (if it's possible!)


1 Answers

Observer pattern to the rescue! Woooosh!

Let your Subject define a method for relaying that object to many listening Observers. You can then dynamically add and remove listeners.

like image 187
Mike Avatar answered Sep 23 '26 01:09

Mike