Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Design Pattern Concepts and Examples

This post helps us learn what design patterns are and how to use them. I have tried to explain the problem statement where we can use these design patterns.

What is a Design pattern?

The “design pattern” is a general reusable solution for a usually occurring problem in software design. Basically, it is a description for how to solve problems that can be used in different circumstances.

The “design patterns” are used for best practices that the programmers can use to solve common occurring problems when designing an application.

The “design patterns” can improve the development process by providing tested, proven development paradigms.

Stayed Informed – What is Repository Pattern?

Why should you use Design Patterns?

The “design patterns” provides us many more advantages when we are designing an application and some of the following advantages as given bellow,
1.      A pattern provides us solution for the common problems which occur in software application.
2.      A pattern provides us common platform to the developers and the developers can be used in any programming languages.
3.      A pattern provides us code reusability, testability and extensibility.
4.      A pattern helps us to improve developer communication.

What are the Advantages of Design Patterns?

The List of Advantages,
1.      A pattern provides us code reusability, testability and extensibility.
2.      A pattern provides us to enabling large scale reuse of S/W code.
3.      A pattern helps us to improve developer communication.
4.      Patterns capture expert knowledge and design. It’s make expertise widely available.
5.      Pattern allows us to change the design of your application more readily.
6.      Pattern allows us to easily test the seam of an application.
7.      And so on..

What are the Disadvantages of Design Patterns?

The List of Disadvantages,
1.      We don’t lead to direct code reuse and complex in nature. I mean we used extra layer in our applications.
2.      The patterns consume more memory because it is in generalized format.
3.      The patters are validated by experience and discussion.
4.      And so on..

What About Anti-patterns?

The selection of wrong design pattern can perform a negative effect on your application codes because it is required to choose appropriate design pattern for you and the selection of wrong design pattern is defined as “anti-pattern”.

Are Design Patterns the same thing as Frameworks?

No!, Both the design pattern and framework are different.  The design pattern provides only the guideline, not codes but framework deals with codes and so on..


What are the Gang of Four (GoF) Design Patterns?

The “design patterns” gained popularity in computer science after the Design Patterns book. Basically, it was published in 1994/95 by four authors Erich Gamma, Richard Helm, Ralph Johnson and John. These four book authors are known as Gang of Four (GoF).

Which Pattern is the Foundation of Design Pattern?

The Gang of Four (GoF) design patterns is the foundation for all other design patterns that is called the mother of design patterns.

What are the types of Design Patterns?
OR
What are the main Categories of (GoF) Pattern?

The “design patterns” are divided in to three main categories and it’s depending on the problem and its solutions. The categories are,

1.      Creational Patterns – The creational patterns are ones that create objects for you, rather than having you instantiate objects directly. This pattern gives us more flexibility in deciding which objects need to be created for a given case.
2.      Structural Patterns - These concern class and object composition. They use inheritance to compose interfaces and define ways to compose objects to obtain new functionality.
3.      Behavioural Patterns – The most of these design patterns are specifically concerned with communication between objects or classes.

What is Creational Design Pattern?

The creational patterns are ones that create objects for you, rather than having you instantiate objects directly. This pattern gives us more flexibility in deciding which objects need to be created for a given case.

We have five types of Design Patterns i.e.
1.      Singleton
2.      Factory
3.      Abstract Factory
4.      Prototype
5.      Builder

What is Structural Design Pattern?

These concern class and object composition. They use inheritance to compose interfaces and define ways to compose objects to obtain new functionality.
We have 6th types of Design Patterns i.e.
1.      Adapter
2.      Bridge
3.      Decorator
4.      Facade
5.      Flyweight
6.      Proxy

What is Behavioural Design Pattern?

The most of these design patterns are specifically concerned with communication between objects or classes.
We have 11th types of Design Patterns i.e.
1.      Chain of responsibility
2.      Command
3.      Interpreter
4.      Iterator
5.      Mediator
6.      Memento
7.      Observer
8.      State
9.      Strategy
10.  Template method
11.  Visitor

What is Factory method pattern?

The factory method pattern is used to create objects at run-time based on your demand. The factory pattern is most commonly used in modern programming languages like C# and Java.

For example, suppose that a bottle factory which produces us different types of bottles. If we went to bottle factory and the order for water-bottles, the factory method will produce water-bottle and will provide us.

When to use Factory method pattern?
The factory method pattern is used when the,
1.      Creation of object is done when it is required.
2.      Flexibility is important.
3.      Sub-classes decide what objects should be created.
4.      And so on..

What is Abstract Factory Pattern?
The abstract factory patterns acts as like “super factory” which creates other factories that is also called Factory of factories pattern.

The abstract factory patterns are used to create a set of dependent objects.  At the time of creating objects this pattern internally use “factory method design pattern” and “prototype design pattern”.

When you use Abstract Factory Pattern?
The abstract factory pattern is used when we need to create a set of dependent objects or related objects.

At the time of creating objects this pattern internally use “factory method design pattern” and “prototype design pattern”.

What is the difference between factory and abstract factory patterns?

The Factory Pattern is used to create objects at run-time based on your demand. The factory pattern is most commonly used in modern programming languages like C# and Java.

The Abstract Factory Patterns acts as like “super factory” which creates other factories that is also called Factory of factories pattern.

The Abstract Factory Patterns are used to create a set of dependent objects.  At the time of creating objects this pattern internally use “factory method design pattern” and “prototype design pattern”.

What is Prototype Pattern?
The prototype patterns are used to create a new object from the existing object instance and these patterns are also used to create a duplicate object of the current object to enhance application performance.

When we use Prototype Pattern?
The prototype patterns are used when the creation of object is so complex.

What is Singleton Pattern?

The Singleton Pattern ensures that a class has only one instance in the across application and the object instance coordinate to across the app.
This pattern is the simplest design patterns and used to restrict the creation of multiple objects instance.

When to use Singleton Pattern?
This pattern is the simplest design patterns and used to restrict the creation of multiple objects instance.

Example as,
//CREATE A CLASS WITH STATIC MEMBERS.
//DEFINE A PRIVATE CONSTRUCTOR TO THE CLASS.
//PROVIDE A STATIC METHOD TO GET ACCESS TO THE SINGLETON OBJECT.
public class SingletonPattern
{
    private static SingletonPattern instance;
    private SingletonPattern() { }

    public static SingletonPattern Instance
    {
        get
        {
            if (instance == null)
            {
                instance = new SingletonPattern();
            }
            return instance;
        }
    }
}

What is MVC Pattern?

The Model View Controller (MVC) is a pattern used in software engineering. It is not a design pattern.  It is a pattern only. The MVC is most popular pattern now.

These patterns separate the applications structure into three parts that are model, view and controller.

1.      Model – The model is responsible for the data access layer and it responds to the requested view and controllers.
2.      View – The view is the presentation layer of the application and also called users interface.
3.      Controller – The controller is the business logic layer for the application and the controller is responsible for responding to user input and performs interactions on the data model objects and also controls to the models and view and controller work between the view and model.
References,
1.      GoF - Gang Of Four
2.      Design Patterns

Stayed Informed - Object Oriented Programming Concepts (OOPs)

I hope you are enjoying with this post! Please share with you friends. Thank you!!


This post first appeared on Programming, please read the originial post: here

Share the post

Design Pattern Concepts and Examples

×

Subscribe to Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×