Alibabacloud.com offers a wide variety of articles about microservices patterns with examples in java, easily find your microservices patterns with examples in java information here online.
object is responsible for creating products in the Windows product family. This is the application of abstract Factory mode, the solution of abstract Factory mode such as: Obviously, a system can only run in a Windows environment of one operating system, but not on different operating systems at the same time. Therefore, the system can actually only consume products belonging to the same product family.In modern applications, the use of abstract Factory mode has been greatly expanded, no longe
=" +intadd.operate (10, 25)); System.out.println ("10.2+25.3=" +doubleadd.operate (10.2, 25.3));//subtraction Factory is responsible for the production of two integer subtraction, And a subtraction of two double types operationfactory of2 = new Addoperationfactory (); Intoperation intsub = Of2.createintoperation ();D Oubleoperation doublesub = Of2.createdoubleoperation (); System.out.println ("10-25=" +intsub.operate (10, 25)); System.out.println ("10.2-25.3=" +doublesub.operate (10.2, 25.3));}}
The intermediary pattern of the Java design pattern is one of the behavioral patterns. Defines a mediation object to encapsulate the interaction between series objects. Intermediaries do not need to refer explicitly to each other, so that they are loosely coupled and can independently alter their interactions.
As shown in the following illustration:
Examples
To implement Java-oriented objects, let's write a simple factory to implement examples of Java encapsulation, inheritance, reuse, and, by the way, a simple factory with functional simplicity.First, simple factory (non-functional)1, first of all, we put the common attribute method in a common class inside/** * Created by LK on 2016/5/8. */public class Operation {
Userwang=NewUser ("Wangwu"); Server.registerobserver (Userzhang); Server.registerobserver (Userli); Server.registerobserver (Userwang); Server.setinfomation ("PHP is the best language in the world!" "); System.out.println ("----------------------------------------------"); Server.removeobserver (Userzhang); Server.setinfomation ("Java is the best language in the world!" "); }}Test results:6. Summary
This pattern i
coupled, interdependent, and thus less reusable. The observer pattern is loosely coupled, so reusability can be improved.When do I use observer mode?
When an object model has two facets, one aspect depends on the other. The two are encapsulated in separate objects so that they can be independently changed and reused.
When a change to an object needs to change other objects at the same time, it is not known how many objects need to be changed.
When an object must notify other ob
The examples in this article describe the Java interface and abstract class usage. Share to everyone for your reference, specific as follows:
Interface
1 because Java does not support multiple inheritance, there is an interface where a class can inherit only one parent class, but can implement multiple interfaces, and the interface itself can inherit multiple i
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.