Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Design Pattern

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

It is used when we have a parent class and we have multiple child classes and the factory

design pattern will give the instance of child class as per the type of instance class you want will
pass in parameter.
There is parent class and child class and factory class and factory class will give the object of
type you pass in parameter.

Prototype Design Pattern


Like we have created one object and we load some initial value in that object from db and now
we have to create another object using that initial value so we can again load the db and set
that initial value so it is better to use value from the first object rather than fetch the data from
db. So in prototype we clone the object or copy the value from one object.
Any changes in the clone object will not reflect back to the original object.
We create constructor private so that objects cannot be created from outside the class.
Method should be static so that we can directly call this method from class name since object
can not be created from outside the class

Eager Initialization
eager initialization means that the singleton instance is created as soon as the class is
loaded into memory.
eager initialization means as soon as the class is loaded in memory object will
* create and initilized in static singleton class variable

Lazy Initialization
Whenever there is need and we will call the method then only object will create and initilze
First it will check weather there is object present or not if not then it will create a object and
initialize and next time when we will call it will give same object

Thread safe method Initialization


This is thread safe method
In above initialization multiple threads can access the method at same time so we can not get
the same object.
In this initialization we create a synchronized method now only one thread can access this
method and we will always get the same instance.

Structural Design Pattern


Proxy Design Pattern
It is used to provide control to the access or feature and to filter the request.like delete
query from database functionality is not applicable to every user it is given only to
admin.

You might also like