Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java Prototype Pattern     - awk variables (Linux)

- There is sort of a directed acyclic graph topology (Programming)

- Vim highlight lookup operation (Linux)

- MySQL + Heartbeat + DRBD deployment architecture (Server)

- Automatic Clear date directory shell script (Linux)

- How to make GRub instead of the default Ubuntu software center (Linux)

- To install and use Docker under linux (Server)

- Java implementation of stacks and queues (Programming)

- Oracle conditional select statements and looping statements (Database)

- Sqoop data export import command (Database)

- WEB-based Android Remote Tools Python implementation (Programming)

- Axel install plug under CentOS 5/6 acceleration yum downloads (Linux)

- Linux Network Programming - raw socket can do (Programming)

- Ubuntu Tutorial: E: Failed to get lock / var / lib / apt / lists / lock - open (Linux)

- GitLab issued Merge Request return error 500 when the two solutions log (Linux)

- Linux boot process and run level (Linux)

- RT-11SJ run at ambient PDP-11 MACRO-11 assembly (Programming)

- GAMIT 10.50 installed in Ubuntu 12.04 system (Linux)

- Nginx1.8 version upgrade method AMH4.2 Free manually compile (Server)

- Linux automatic installation and implementation (Linux)

  Java Prototype Pattern
  Add Date : 2017-08-31      
  Prototype schema definition: Use the prototype instance to specify the type of object to be created, and create a new object by copying those prototypes.

The Prototype pattern allows an object to create another customizable object without any knowledge of how to create it. It works by passing a prototype object to the object to be created. The object to be created is created by requesting the prototype Objects copy themselves to implement the creation.

How to use Prototype mode

Because Java provides clone () method to achieve the object cloning, so the Prototype pattern to achieve all of a sudden become very simple. Take the spoon as an example:

Public abstract class AbstractSpoon implements Cloneable {
String spoonName;
Public void setSpoonName (String spoonName) {this.spoonName = spoonName;}
Public String getSpoonName () {return this.spoonName;}
Public Object clone () {
Object object = null;
Try {
Object = super.clone ();
} Catch (CloneNotSupportedException exception) {
System.err.println ( "AbstractSpoon is not Cloneable");
Return object;
There are two concrete implementations (ConcretePrototype):

Public class SoupSpoon extends AbstractSpoon {
Public SoupSpoon () {
SetSpoonName ( "Soup Spoon");
Public class SaladSpoon extends AbstractSpoon {
Public SaladSpoon () {
SetSpoonName ( "Salad Spoon");

Calling the Prototype pattern is simple:

AbstractSpoon spoon = new SoupSpoon ();
AbstractSpoon spoon = new SaladSpoon ();

Of course, can also be combined with the factory pattern to create AbstractSpoon instance.

Prototype in Java into a clone () method of use, because of the pure Java object-oriented features, making use of design patterns in Java become very natural, the two are almost seamless. This is reflected in many patterns, such as the Interator traversal pattern.
- Linux Command Study Notes (Linux)
- The simple multi-threaded Python (Programming)
- To create someone else can not afford to delete the administrator user (Linux)
- High-performance JavaScript loops and flow control (Programming)
- Reason C ++ program running under Linux a segmentation fault core dumped in (Programming)
- Docker improve safety (Server)
- Android Studio interface-related settings (Linux)
- Ubuntu derivative version of the user and how to install SmartGit / HG 6.0.0 (Linux)
- How to install Ubuntu strategy game Wesnoth 1.12.0 (Linux)
- Teach you the Ubuntu Server enabled SSH multifactor authentication (Server)
- Linux operating system boot manager -GRUB (Linux)
- Java code JIT compiler-friendly Mody (Programming)
- Using LLVM Clang and Blocks under Linux (Programming)
- Performance Optimization: Using Ramlog transfer log files to memory (Linux)
- Give your photos Instagram style filters plus program in ubuntu (Linux)
- C # DateTime structure common method (Programming)
- Create a custom pixel format based on an existing image data BufferedImage (Programming)
- Teach you how to ensure password security under the Linux operating system (Linux)
- CentOS7 install NTFS-3G driver (Linux)
- Eclipse 3.7.2 can not start solving under Ubuntu 14.04 (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.