Thursday 26 July 2012

Design patterns in .net



What are Design Patterns?

To say what design patterns are in a single sentence is difficult but we can say as design patterns are :
Solutions to recurring design problems.
They are a set of rule which help the developer to accomplish a certain task.
Design patterns are architectural patterns and generalized solutions , which can be applied when needed.
These are standardized and efficient solutions to software design and programming problems that are re-usable.
Generally Gang-of-Four(GoF) are used.

Why to Use Design Patterns?

Design patterns are proven solution templates, using design templates not only reduces the overhead of architecting a solution afresh but these are also  optimized ,easy to do , easy to learn solutions.


What are the common design patterns used?

CREATIONAL
creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation
STRUCTURAL
Design Patterns that ease the design by identifying a simple way to realize relationships between entities.
BEHAVIOURIAL
Identify common communication patterns between objects and realize these patterns.


CREATIONAL PATTERNS

  Abstract Factory
  Creates an instance of several families of classes
  Builder
  Separates object construction from its representation
  Factory Method
  Creates an instance of several derived classes
  Prototype
  A fully initialized instance to be copied or cloned
  Singleton
  A class of which only a single instance can exist


STRUCTURAL PATTERNS

  Adapter
  Match interfaces of different classes
  Bridge
  Separates an object’s interface from its implementation
  Composite
  A tree structure of simple and composite objects
  Decorator
  Add responsibilities to objects dynamically
  Facade
  A single class that represents an entire subsystem
  Flyweight
  A fine-grained instance used for efficient sharing
  Proxy
  An object representing another object

BEHAVIORIAL

  Chain of Resp.
  A way of passing a request between a chain of objects
  Command
  Encapsulate a command request as an object
  Interpreter
  A way to include language elements in a program
  Iterator
  Sequentially access the elements of a collection
  Mediator
  Defines simplified communication between classes
  Memento
  Capture and restore an object's internal state
  Observer
  A way of notifying change to a number of classes
  State
  Alter an object's behavior when its state changes
  Strategy
  Encapsulates an algorithm inside a class
  Template Method
  Defer the exact steps of an algorithm to a subclass
  Visitor
  Defines a new operation to a class without change

Patterns I have used?

I have used Creational and Structural and have never implemented any Behaviorial Pattern.

In Creational I have used:
  • Abstract Factory
  • Factory Method
  • Singleton Method

In Structural I have used
  • Adapter Pattern
  • Facade Pattern
Other patterns I know are:
  • Decorator
  • Builder
  • Iterator


Can we create our own pattern?

Whenever a certain solution that is reusable in a vast majority of your projects, it can be abstracted to a design pattern and cab be used across the organisation.

No comments:

Post a Comment