Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java Builder mode     - Ubuntu users install the video driver Nvidia Driver 334.21 (Linux)

- JavaScript closures and the scope chain (Programming)

- UNIX how to restrict users by IP Telnet (Linux)

- CentOS 6.5 install VNC-Server (Linux)

- Getting Started with Linux system to learn: how to install the kernel headers on Linux (Linux)

- Select helps secure the system network management tools (Linux)

- Git / Github use notes (Linux)

- Scala REPL Shell call (Programming)

- 22 Port weak passwords and SSH connection program of the Linux server (Linux)

- CentOS7 method to upgrade the kernel to 3.18 (Linux)

- CentOS5 installation Nodejs (Linux)

- OpenGL ES 3.0 vertex buffer (Programming)

- Installation in lxml Python module (Linux)

- Profile Linux users login shell and login to read (Linux)

- CentOS 7 Docker build private warehouse registry (Linux)

- Ubuntu file security removal tool (Linux)

- Linux file content inspection - cat, tac, no, more, less, head, tail, od (Linux)

- Define and modify strings principle in Python (Programming)

- Use LKM change the default linux security level (Linux)

- Netapp storage routine inspections and information gathering (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.
- Yii PHP Framework Getting Started tutorial (Linux)
- The Sublime Text 3 configuration file (Linux)
- Let 32 Linux / CentOS system to support more than 4G memory (Linux)
- Linux memory Cache Analysis (Linux)
- Inherent limitations of Linux systems network security (Linux)
- Linux Log File Browser --logrotate (Linux)
- C ++ pointer two third memory model (Programming)
- CentOS system Amoeba + MySQL Master-slave configuration (Database)
- Android Activity launchMode (Programming)
- CentOS 6.4 (64bit) install Python 2.7.5 (Linux)
- MySQL restart process can not be taken lightly (Database)
- MySQL Installation Troubleshooting (Database)
- 20 Top Linux commands (Linux)
- Three binary tree traversal (recursive, non-recursive traversal and Morris) (Programming)
- Git uses a basic tutorial (Linux)
- Linux, modify / etc / profile file (Linux)
- Import and export myloader accelerate mydumper (Database)
- Docker study notes (Server)
- Mongo-connector integrated MongoD to achieve incremental Solr index (Server)
- Linux operating system to solve a serious fault handling (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.