The document describes several creational design patterns including Singleton, Factory Method, Abstract Factory, Builder, and Prototype. The Singleton pattern ensures that only one instance of a class is created while the Factory Method pattern defines an interface for creating objects but lets subclasses decide which class to instantiate. The Abstract Factory pattern provides an interface for creating families of related objects without specifying their concrete classes. The Builder pattern separates object construction from its representation and the Prototype pattern creates objects by cloning existing object prototypes.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
39 views
Pattern Use Idea Example: Singleton
The document describes several creational design patterns including Singleton, Factory Method, Abstract Factory, Builder, and Prototype. The Singleton pattern ensures that only one instance of a class is created while the Factory Method pattern defines an interface for creating objects but lets subclasses decide which class to instantiate. The Abstract Factory pattern provides an interface for creating families of related objects without specifying their concrete classes. The Builder pattern separates object construction from its representation and the Prototype pattern creates objects by cloning existing object prototypes.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4
Creational Patterns
Pattern Use idea example
Singleton Create only one instance of a ‐ Create static private instance of the class ‐ Ball in pes
given class ‐ Make the Constructor Private game ‐ Static Public Interface to Access an Instance Factory Customer does not know which ‐ Create class factory ‐ Person – male class has to be used to create ‐ Create Public function return type of Parent class – female the object
Abstract factory an abstract factory is a class ‐ Create abstract class contains all shared functions ‐
that provides an interface to produce a family of objects
Builder Separate the construction of a ‐ Create Builder of object (Contains functions of ‐ order
construction of object + getObject : object complex object from its ‐ Create Director which save steps of construction representing so that the same 1‐n aggregation – contains instance builder & construction process can create build() different representations
Prototype Provides a simpler way of ‐ main class implements Cloneable , override clone ‐ useraccount –
creating an object by cloning it ‐ shallow teacher account from an existing (prototype) object. TIME
Structural Patterns Pattern Use idea example
Composite ‐ Lets clients treat individual ‐ inheritance , shared function become abstract ‐ file – folder
objects and compositions of ‐ functions that not shared throw ‐ getfiles objects uniformly SpecialExciption ‐ compositeObject with its parent – aggregation 0‐n Flyweight ‐ Memory ‐ Set intrinsic(common) extrinsic (unique for ‐ Vacancy ‐ Use sharing to support large every instance ) numbers of objects ‐ Create my class ‘contains flyweight obj’ efficiently. ‐ Create interface for Intrinsic information ‐ Implement it as singleton ‐ Create singleton factory contains ‐ getfactory , getflywieht ‐ Map of flyweight Decorator ‐ Extends the functionality of ‐ Create decorator abstract class (wrapper ), ‐ icecream an object in a manner ‐ Contains instance ( new functionality ) that is transparent to its ‐ Simple obj implement main interface clients without using ‐ New function extends decorator inheritance. ‐ At runTime adapter ‐ Update ‐ Create adapter class ‐ Audio player Convert the interface of a class ‐ Contains private object of new functionality into another interface clients ‐ Implement adapte class interface expect. Lets classes work together Add private adapter object to main class that couldn't otherwise because of incompatible interfaces. Facade ‐ Complex task done with one ‐ Create class contains all components of ‐ Computer click subsystem make them private and don’t have startup getters. ‐ Create function oneClick Pattern Use idea example
Chain of Responsibility ‐ recommends a low degree of ‐ create interface contains ‐ dispense
coupling between an object that ‐ main function sends out a request and the set of ‐ setnextHandler potential request handler objects ‐ When there is more than one object that can handle or fulfill a client request ‐ request reaches the end of the chain without getting processed Virtual proxy To provide the required functionality to ‐ Create virtual class contains ‐ Emailservices allow the ondemand creation of a ‐ Implement same real class ‐ windowsServices memory intensive object (until required). interface ‐ Fast on startup ‐ Private object of real Class ‐ Add if condition to test build of real obj Mediator Encapsulates the direct object‐to‐object ‐ Create interface mediator ‐ Chat with group communication ‐ Contains send function ( all expect details among a set of objects in a me) separate (mediator) ‐ Add function Object object. This eliminates the need for these ‐ add protected mediator obj to all objects objects to interact with each other directly. ‐ Request sends to all expect me Visitor Allows an operation to be defined across ‐ Add abstract accept function in ‐ a collection main class of different objects without changing the ‐ Implement it in all types of classes of element objects on which it operates ‐ Create visitor interface contains all needed functions functions , implement it Iterator Provide a way to access the elements of ‐ Implement Enumeration ‐ KidClub an aggregate object sequentially without Implement all of its functions exposing its underlying representation Hasmoreelemnts() Nextelemnt()