Skip to content

Design Pattern

August 11, 2009

Lazy Initilization Pattern :

During Instance Initialization or Class Initialization, some instance variables can be costly to initialize (either in terms of memory or time) and, indeed, they may never be used.So to avoid this problem Lazy Initilization is introduced. It is the tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed.

Object Pool Pattern :

Thousands of objects are needlessly being killed in every applicaton. Developers are thoughtlessly creating new objects, even though it can be reused they are not thinking of it .They destroy the object and recreating it again so that your memory and CPU time is waited. An object pool is a set of initialised objects that are kept ready to use, rather than allocated and destroyed on demand. A client of the pool will request an object from the pool and perform operations on the returned object. When the client has finished with an object, it returns it to the pool, rather than destroying it.

Prototype Pattern:

The Prototype pattern enables a class to create objects that implement a known interface by giving it a prototypical instance of each kind of object it will create. This pattern is used for example,

¬タᄁ      to avoid subclasses of an object creator in the client application, like abstract factory pattern does.

¬タᄁ      or when the inherent cost of creating a new object in the standard way (e.g., using the ‘new’ keyword) is prohibitively expensive for a given application.

Singleton Pattern:

To avoid using ¬タリn¬タル number of instance being created in class. Since it occupies more memory, waste CPU time and unnecessary resource utilization etc., so to overcome this Single Pattern is introduced. If a system only needs one instance of a class, and that instance needs to be accessible in many different parts of a system, control both instantiation and access by making that class a singleton. This is useful when exactly one object is needed to coordinate actions across the system.

Composite Pattern:

When dealing with tree-structured data, programmers often have to discriminate between a leaf-node and a branch. This makes code more complex, and therefore, error prone. So to avoid this Composite pattern is introduced. Composite allows a group of objects to be treated in the same way as a single instance of an object. Composite can be used when clients should ignore the difference between compositions of objects and individual objects. If you find that you are using multiple objects in the same way, and often have nearly identical code to handle each of them, then Composite is a good choice; it is less complex in this situation to treat primitives and composites as homogenous.

Flyweight Pattern:

A Flyweight is an object that minimizes memory occupation by sharing as much data as possible with other similar objects; it is a way to use objects in large numbers when a simple representation would use an unacceptable amount of memory. Often some parts of the object state cannot be shared and it’s common to put them in external data structures and pass them to the flyweight objects temporarily when they are used.

Proxy Pattern:

A proxy, in its most general form, is a class functioning as an interface to another thing. The other thing could be anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate.

Template Pattern:

Two different components have significant similarities, but there is no reuse of common interface or implementation for both components. If a change common to both components becomes necessary, duplicate effort must be finished. So to make use of duplicate effort Template Pattern is introduced. Define the skeleton of an algorithm in an operation, deferring some steps to client subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: