Example of realizing multi person chat room function based on mediator mode in Java
This paper illustrates how Java implements the function of multi person chat room based on mediator mode. Share with you for your reference, as follows:
The first mock exam definition
The mediator model encapsulates the interaction between a series of objects with a mediation object, so that other object instances do not need to be explicitly referenced in each object, so as to reduce the coupling between each object, and the interaction relationship between objects can be changed independently.
Two example
1 mode analysis
The first mock exam is to explain this pattern by using multiplayer chat rooms.
2. Mediation mode static class diagram
3 code example
3.1 intermediary interface - imeditor
3.2 mediator implementation - concretemediator
3.3 user interface - iuser
3.4 abstract user - abstractuser
3.5 user a -- usera
3.6 user B -- userb
3.7 user C - userc
3.8 running a multiplayer chat room
4 operation results
III. design principles of the mode
1. One to many object dependencies are transformed into one to one dependencies. 2. Centralized control improves the reusability of classes
IV. application occasions
(1) A group of objects communicate in a well-defined but complex way, resulting in interdependence, chaotic structure and difficult to understand. Note the interdependence between multiple objects. (2) If you want to customize a behavior distributed in multiple classes without generating too many subclasses. (3) The research and development of product architecture needs more occasions that are easy to expand.
V. static class diagram of mediation mode
For more Java related content, interested readers can view the special topics of this site: introduction and advanced tutorial of java object-oriented programming, tutorial of Java data structure and algorithm, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills