Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In this instance the chat and game windows would be considered Observers. You'll want to implement an interface called something like Observers (the java API has a native Observer pattern at java.util.Observer but you can implement your own) and have your chat and board window implement them. You might have it look like:</p> <pre><code>public interface Observer { public void postUpdate(String newData); } </code></pre> <p>postUpdate is a function that all of the Observers will need to define, and both these classes and anything else you want to include later will need to implement Observer, like:</p> <pre><code>public class ChatWindow Implements Observer { //bla bla bla } </code></pre> <p>Then, in your network class, you'll want a method like</p> <pre><code>public void addObserver(Observer newObserver) { //Do something here to add the new Observer to some list of Observers, maybe a //List&lt;Observer&gt; or something? } </code></pre> <p>Then, during initialization, you will want to want to call the addObserver function from each Observer you want to have watching it, and have some logic in your network class to update everybody who has registered by calling their postUpdate functions. In this case I acted as though you want to send them a String containing new data, that is only one option. You could also have it pass nothing and just act as notification that an update has occured in which case the Observers will be responsible for checking if the data they care about from the network has changed; or maybe you could have it pass some data representing what exactly has been updated on the network, such that the class could know if it cares about what has changed (for example, the gameboard might not care if the only change has occured to chat data, so it won't bother doing anything else).</p> <p>You may find best success investigating Head First Design Patterns, in terms of books.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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