Java Inter Application Form Communication Observation Template

Observer pattern? Where can I get examples of this in Java (I know Google, but was hoping for some personal understanding).

To the correct explanation of my problem:

I have 3 shapes / windows. A whiteboard is the main form that loads as an application.

Chat is a text chat.

"network" is where the network connection is established.

I have a game (connect4) running locally, and I would also like to implement a network version.

My idea is probably related to the Observer template to have a stream (or something) that monitors the network status at runtime, as well as updating chat forms and whiteboards of the current network status, as well as delivering received data from the network.

Are my ideas valid? or how do I need to install network and network status updates throughout the application?

Thank you for your input.

panel http://img39.imageshack.us/img39/5221/boardz.jpg

chat http://img691.imageshack.us/img691/3629/chatos.jpg

network http://img441.imageshack.us/img441/5906/networks.jpg

EDIT: Is there a Java Observer template book that I can recommend?

+3
source share
3 answers

In this case, chat and game windows will be considered Observers. You will want to implement an interface called “Observers” (the java API has its own Observer template on java.util.Observer, but you can implement it), and your chat and whiteboard window implements them. Perhaps it looks like this:

public interface Observer 
{
public void postUpdate(String newData); 
}

postUpdate - , , , , Observer, :

public class ChatWindow Implements Observer
{
//bla bla bla
}

public void addObserver(Observer newObserver)
{
//Do something here to add the new Observer to some list of Observers, maybe a
//List<Observer> or something?
}

addObserver , , , , , postUpdate. , , , . , , , , ; , , , , , , , (, , , - ).

Head First Design Patterns .

0

Java. , .

, - . RMI, Caucho, HTTPInvoker?

"", . .

, StackOverflow - . .

+1

Source: https://habr.com/ru/post/1744207/


All Articles