Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Creative pattern: prototype pattern

Shulou Source: shulou.com Published: 2022-06-03 05:35:22 09月14日 Update

The article begins with:

Creative pattern: prototype pattern

The fifth of the five major creative models: the prototype model.

Brief introduction

Name: prototype pattern

English name: Prototype Pattern

Values: efficiency first

Personal introduction:

Specify the kinds of objects to create using a prototypical instance,and create new objects by copying this prototype.

Specify the type of object to be created with prototype instances, and create new objects by copying these prototypes.

(from the Zen of Design patterns)

It's the last article in a series, and today is the last article in creating a pattern. What is a creative model? The creative pattern abstracts the instantiation process of the class, which separates the creation and use of objects, thus making the code more flexible.

One of the most commonly used ways to create an object is new ABC (), which creates an object directly through the constructor. To create an object through the prototype pattern, you can create an object without calling the constructor. Let's unveil it.

The story you want.

A few days ago, a teacher from a publishing house invited to write a book. In view of the fact that he knew that his level was not good enough to publish a book, he did not cooperate and was still studying hard. He had the ability and opportunity to reconsider this aspect in the future.

Today's story begins with the publication of a book. We know that when a new book is published, many copies will be made, and if it sells well, there will be many printed editions. Let's learn how the process of photocopying a batch of books is realized. Xiaoming wrote down the following code.

Public class NoPrototypeTest {public static void main (String [] args) {for (int I = 1; I)

Tags: Books entertainment copying patterns instances objects prototypes codes methods copies principles that is Xiaoming interfaces results problems efficiency tutorials processes BMW Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS OPPO Reno Microsoft vpn Apple