Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Creative pattern: prototype pattern

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report