Click here to Skip to main content
14,693,384 members
Articles » Graphics / Design » Windows 8 Design » Design
Technical Blog
Posted 14 May 2013

Tagged as

(untagged)

Stats

14.7K views
8 bookmarked

Introduction to Design Patterns

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
14 May 2013CPOL
An introduction to design patterns

Introduction

Once in a while, every developer goes through the term design pattern, analyzes these patterns and eventually uses them in various code. So the question first arises in mind as to what’s the design pattern, what did they do and how did they do it. We start with answering the first question here.

Definition

Design Pattern is a general reusable solution to a commonly occurring problem within a given context.

What exactly does this mean ??? Let's try to understand.

What did we do when we get a problem to solve which is new to us? Google it and check if somebody already solved our problem. Exactly like this case, each design pattern has an already available solution to solve some particular problems that we encounter while designing logic or writing code for our applications.

Now let’s explore various types of Design Patterns. Design patterns are mainly categorized into three types:

  1. Creational Patterns: Creational patterns are used to construct objects such that they can be decoupled from their implementing system.
    Examples of creational patterns are:
    • Abstract Factory: Create instances of classes belonging to different families
    • Builder: Separate representation and object construction
    • Factory: Create instances of derived classes
    • Prototype: Clone or copy initialized instances
    • Singleton: Class with only one single possible instance
  2. Structural Patterns: Structural patterns are used to form large object structures between many disparate objects.
    Examples of structural patterns are:
    • Adapter: Match interfaces of classes with different interfaces
    • Bridge: Separate implementation and object interfaces
    • Composite: Simple and composite objects tree
    • Decorator: Dynamically add responsibilities to objects
    • Facade: Class that represents subclasses and subsystems
    • Flyweight: Minimize memory usage by sharing as much data as possible with similar objects
    • Proxy: Object that represents another object
  3. Behavioral Patterns: Behavioral Patterns are used to manage algorithms, relationships, and responsibilities between objects.
    Examples of behavioral patterns are:
  • Chain of Responsibility: Pass requests between command and processing objects within a chain of object
  • Command: Encapsulate a method call as an object containing all necessary information
  • Interpreter: Include language elements and evaluate sentences in a given language
  • Iterator: Give sequential access to elements in a collection
  • Mediator: Encapsulates and simplifies communication between objects
  • Memento: Undo modifications and restore an object to its initial state
  • Observer: Notify dependent objects of state changes
  • State: Change object behavior depending on its state
  • Strategy: Encapsulate algorithms within a class and make them interchangeable
  • Template: Define an algorithm skeleton and delegate algorithm steps to subclasses so that they may be overridden
  • Visitor: Add new operations to classes without modifying them

In design pattern, we often listen to the term Gang of Four, GOF, or GO4. Gang of four is nothing to do with technical sense, it’s name of four authors(Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides) of book Design Patterns: Elements of Reusable Object-Oriented Software.

In the following posts, I will pick each one of the original 23 GOF design patterns, discuss the pros, cons and need, UML diagrams for patterns and simple code illustration in C#.

www.HyperSmash.com


Image 1

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

PRANAV SINGH
India India
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 Pin
Mohammed Hameed15-May-13 5:11
professionalMohammed Hameed15-May-13 5:11 
GeneralNice Pin
Tarek Elqusi15-May-13 0:19
professionalTarek Elqusi15-May-13 0:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.