Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java Builder mode     - Firewall types and instructions (Linux)

- The top command under Linux (Linux)

- How to install and use the malware detection tool LMD and ClamAV antivirus engine on Linux (Linux)

- Java to achieve local fileCopy (Programming)

- Git uses a standard process (Linux)

- Linux system security settings after installation (Linux)

- Configuring automatic mail GAMIT under CentOS system (Linux)

- CoreOS use register mirror to build private warehouse (Linux)

- Generators and iterators in Python (Programming)

- Linux system Perl Lite netstat (Linux)

- Linux argument references and command substitution (Linux)

- Linux file permissions and access modes (Linux)

- Linux automatically install service components and optimize the kernel parameters (Linux)

- PostgreSQL using the system cache to improve operational efficiency (Database)

- 10 Nginx safety tips (Linux)

- How SSHfs mount a remote file system on Linux (Linux)

- OpenStack Folsom create an instance of the failure of the Quota Fixed_IP articles (Server)

- Let your PHP 7 faster the Hugepage (Linux)

- C ++ 11 smart pointers (Programming)

- Single Instance ASM under CRS-4124, CRS-4000 error handling (Database)

 
         
  Java Builder mode
     
  Add Date : 2017-08-31      
         
       
         
  Builder schema definition: The construction of a complex object with its representation of separation, making the same building process can create a different representation.

The Builder pattern is a step-by-step process of creating a complex object that allows the user to build them by specifying only the type and content of the complex object. Users do not know the specific details of the internal building. Builder mode is very similar to the abstract factory pattern, the slight difference probably only in the repeated use can be realized.

Why Builders

Is to decouple the process of building a complex object from its components. Note: The decoupling process and components.

Because a complex object, not only has a lot of components, such as cars, there are many components: wheels, steering wheel, engine, and a variety of small parts, etc., many parts, but far more than these, how these components assembled into a Car, the assembly process is also very complex (requires a good assembly technology), Builder mode is to separate parts and assembly process.

How to use builder mode

First, assume that a complex object is composed of multiple components, Builder model is the creation of complex objects and components were created separately, respectively, with the Builder class and Director class to represent.

First, you need an interface that defines how to create individual parts of a complex object:

Public interface Builder {
// Create part A for example to create a car wheel
Void buildPartA ();
// Create part B for example to create a car steering wheel
Void buildPartB ();
// Create part C for example to create a car engine
Void buildPartC ();
/ / Back to the final assembly of finished products (return to the final assembly of a good car)
/ / Assembly of the finished product is not here, but transferred to the following Director class.
// Decoupled processes and components are implemented
Product getResult ();
}}
With the Director to build the final complex objects, and in the above Builder interface is how to create a package components (complex objects are composed of these components), that is, Director's content is how the components assembled into the final product:

Public class Director {
Private Builder builder;
Public Director (Builder builder) {
This.builder = builder;
}}
/ / Part will be part of the final partA partB partC complex objects
// Here is the process of assembling the wheel steering wheel and the engine into a car
Public void construct () {
Builder.buildPartA ();
Builder.buildPartB ();
Builder.buildPartC ();
}}
}}
Builder concrete concreteBuilder:

Through the specific interface Builder to complete the assembly or assembly of the product components;
Define and define what it is to create concrete things;
Provides an interface to retrieve the product.
Public class ConcreteBuilder implements Builder {
Part partA, partB, partC;
Public void buildPartA () {
/ / Here is how to build partA specific code
};
Public void buildPartB () {
/ / Here is how to build the specific partB of the code
};
Public void buildPartC () {
/ / Here is how to build the specific partB of the code
};
Public Product getResult () {
/ / Return to the final assembly of finished products
};
}}
Complex Object: Product Product:

    Public interface Product {}
Components of complex objects:

    Public interface Part {
Let's see how to call the Builder pattern:

ConcreteBuilder builder = new ConcreteBuilder ();
Director director = new Director (builder);
Director.construct ();
Product product = builder.getResult ();
Application of Builder Mode

In the actual use of Java, we often use the "pool" (Pool) concept, when the resource provider can not provide adequate resources, and these resources need to be repeatedly shared by many users, you need to use the pool.

"Pool" is actually a memory, when the pool has some complex resources "broken limbs" (such as database connection pool, and sometimes a connection will be interrupted), if the recycling of these "broken limbs" will improve memory use Efficiency, improve the performance of the pool. Modify the Builder class in the Director class to enable it to diagnose which part of the broken limb it is on, and then repair the component.
     
         
       
         
  More:      
 
- Spark On YARN cluster installation deployment (Server)
- Android using SVG vector graphics to create cool animation effects (Programming)
- Source encountered problems and solutions when installing SaltStack (Server)
- Spring loaded container finishes executing a method (Programming)
- Linux server dual-card dual-IP and single-card dual-IP configuration method (ReHat / CentOS) (Server)
- Oracle for Oracle GoldenGate to achieve a one-way synchronization DDL operations (Database)
- How to create a bootable USB disk to use MultiSystem on Ubuntu (Linux)
- CentOS 6.6 permanent method to modify the DNS address (Linux)
- SSH Filesystem use a secure connection for network file system (Linux)
- Node.js development environment deployment (Server)
- Struts2 : combobox label use (Programming)
- Three minutes to teach you to easily grasp the grep command regular expression (Linux)
- MySQLbinlog combat on using data recovery (Database)
- Java synchronization mechanism used in locking Thought (Programming)
- Ubuntu 14.04 set auto sleep time (Linux)
- MBR partitions under Linux (Linux)
- CentOS6 MongoDB connection solution can not break 1000 (Database)
- FileZilla 3.10.1.1 install on Ubuntu 14.10 (Linux)
- Ubuntu dual-card system configuration method (Server)
- Let MySQL 5.6 support Emoji expression (Database)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.