Design Patterns Prototype Pattern - Design Patterns

What is Design Pattern Prototype Pattern?

Prototype pattern refers to create replacement object while keeping presentation in brain. This type of design pattern comes under creational pattern as this example provides one of the best traditions to create an entity.

This pattern involves implementing a prototype line which tells to produce a clone of the current object. This pattern is used when design of object directly is valuable. For instance, an object is to be created after a costly database operation. We can cache the object, returns its clone on next call and update the database as and when needed thus dipping database calls.

Implementation

We're going to create a summary class Shape and real classes extending the Shape class. A class Shape Cache is defined as a next step which supplies shape objects in a Hash table and income their clone when request.

PrototypPatternDemo, our demo category will use Shape Cache class to get a form entity.
prototype_pattern_uml_diagram

Step 1

Make an abstract class implement Closable line.

Shape.java

Step 2

Create concrete classes extending the beyond class.

Rectangle.java

Square.java

Circle.java

Step 3

Generate a class to get real classes from folder and layup them in a Hash chart.

ShapeCache.java

Step 4

PrototypePatternDemo uses Shape Cache class to obtain clone of shapes store in a Hash table.

PrototypePatternDemo.java

Step 5

Prove the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Design Patterns Topics