Você está na página 1de 11

Design

Design Patterns
Patterns
CE00362-3
CT070-3-3

Creational Pattern Prototype


Introduction & Overview

CT070-3-3 - Design Patterns Prototype Slide 1 (of 12)


Learning Outcomes

At the end of this session, you should be


able to;

Describe benefits of Prototype pattern


Recognise and apply Prototype pattern
given a scenario

CT070-3-3 - Design Patterns Prototype Slide 2 (of 12)


Prototype Pattern

Name : Prototype Pattern

Problem :Application "hard wires" the class of object to


create in each "new" expression.

CT070-3-3 - Design Patterns Prototype Slide 1 (of 18)


Prototype Pattern
Context:

Specify the kinds of objects to create using a prototypical


instance, and create new objects by copying this
prototype.

CT070-3-3 - Design Patterns Prototype Slide 1 (of 18)


Prototype Method

Forces:
As a class developer, you ordinarily furnish your class
with constructors to let client applications instantiate it.
We would like to conceal object creation from clients
using a different approach from the ones used by
Builder, Factory Method and Abstract Factory Method.

CT070-3-3 - Design Patterns Prototype Slide 4 (of 12)


Prototype Pattern
Solution
Client - creates a new object by asking a prototype
to clone itself.(use clone() method in java)
Prototype - declares an interface for cloning itself.
ConcretePrototype - implements the operation for
cloning itself.

CT070-3-3 - Design Patterns Prototype Slide 1 (of 18)


Prototype-Class Design

CT070-3-3 - Design Patterns Prototype Slide 1 (of 18)


Definition Prototype Method

Copies or clones an existing class rather


than creating a new instance when
creating new instances is more expensive.

CT070-3-3 - Design Patterns Prototype Slide 6 (of 12)


Prototype Pattern Demo

Client Demo

CT070-3-3 - Design Patterns Prototype Slide 1 (of 18)


Question and Answer Session

Q&A

CT070-3-3 - Design Patterns Prototype Slide 11 (of 12)


References

Steven John Metsker, Design Patterns Java


Workbook, Addison Wesley

Erich Gamma et. al., Design Patterns


Elements of Reusable Object-Oriented
Software, Addison Wesley

CT070-3-3 - Design Patterns Prototype Slide 12 (of 12)

Você também pode gostar