Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java Builder mode     - Upgrade installation manual CentOS6.5 GCC4.8.2 (Linux)

- Oracle conditional select statements and looping statements (Database)

- Install OpenGL development environment in Fedora and Ubuntu (Linux)

- Ubuntu and Archlinux install Notepadqq 0.50.2 (Linux)

- How to fix apt-get update can not add a new CD-ROM error (Linux)

- Sort search algorithm Java - application examples with recursive dichotomy (Programming)

- VirtualBox virtual machine to install Linux (Linux)

- ssh using scp: / directory: Permission denied (Server)

- Linux print file and send mail (Linux)

- Storm basic framework for analysis (Programming)

- IntelliJ IDEA run in Mac10.9 and JDK7 environment (Linux)

- Java Adapter Mode (Programming)

- CentOS 6.5 upgrade to CentOS 7 (Linux)

- Spring AOP for logging (Programming)

- Linux Security Setup Guide (Linux)

- DRBD daily management (Server)

- Linux System Getting Started Learning: Linux how to install 7zip (Linux)

- The script Linux command (Linux)

- Android components save state series - Activity (Programming)

- RHEL7 unattended automatic installation DHCP + TFTP + SYSLINUX + TFTP + Kickstart (Linux)

 
         
  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:      
 
- Unable to solve the official version of Android Studio online update problem (Linux)
- Hibernate + JUnit test entity class generate database table (Programming)
- I use the desktop environment in GNU / Linux combination tool (Linux)
- The compiler installed Kaldi under Ubuntu 12.04 (Linux)
- Configuring a Linux operating system security management services (Linux)
- Hadoop 2.6.0 stand-alone / pseudo-distributed installation (Server)
- To protect the temporary files for Linux security (Linux)
- Nginx Beginner Guide (Server)
- Lenovo E431 notebook CentOS system is installed wireless network card driver (Linux)
- ARM platform compiler installation Golang (Linux)
- OpenNMS separate database (Server)
- Ora-1092: OPI colleague K aborting process --- killed by OO Well killer (Database)
- Python script running in the background (Programming)
- To access an Oracle database using Instant Client (Database)
- Graphic Git (Linux)
- Firewall Configuration Red Hat Enterprise Linux 4 (Linux)
- Is Linux the most secure operating system (Linux)
- The direct insertion sort algorithm (Programming)
- RHEL 6.4 installed MySQL 5.6.27 (Database)
- X security settings in Ubuntu (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.