Software Design Pattern: Why to use & its types

What is design pattern in software architecture?

A pattern basically describes a problem which occurs over and over again in the environment. It describes the core solution to the problem in such a way that you can use this solution a million times without doing it twice. Design patterns play an important role in Software Engineering Architecture as we try to simply the solutions and reusing the old solutions go a long way in cutting down the costs. A software design pattern acts as a template for future software development projects.

How to use software design pattern in software engineering?

  • Read the pattern once through an overview. Pay special attention to the applicability and consequences of using the design pattern in the application. 
  • Before using the design pattern in the application, it is necessary to understand the classes and objects used in the pattern. 
  • Look at the sample code section to make correct use of the design pattern. 
  • Define the class which uses the design pattern. Interfaces, inheritance relationships and instance variable have to be defined properly.

Types of software design patterns in software architecture

  1. Creational design pattern
    Creational design pattern abstract the instantiation process. They help in making the system independent of how its objects are created, composed and represented. Object creation is a complex task. Design pattern resolves this problem.
    Different types of creational design pattern:
    • Factory Method Pattern
      In factory method design pattern, we define an interface and abstract class for creating the object and we let the sub-classes decide which class to instantiate. In short, sub-classes are responsible for instantiating the sub-classes.
    • Abstract Factory Pattern
      Abstract Factory class is that which defines an interface or abstract class for creating families of related of dependent or independent objects. It is similar to Factory method but it produces a collection of classes or objects.
    • Singleton Pattern
      Singleton design pattern in Java is used to define a class that has only one instance .The instance can be created at run time or compile time.
    • Builder Pattern
      Builder pattern is the pattern through which a complex object is created from simple objects through a step by step process. Basically it provides a clear distinction between construction and representation of objects. Construction of the code can be done easily with help of Builders pattern. It will support if there is any change in the representation of objects.
    • Object Pool Pattern
      Creation of an object is a costly affair. So the basic principle behind the object pool pattern is that an object container has been created and whenever any of the objects is required then we can take object from that container and once there is no object in the container then we put more objects in the container.
  2.  Structural design pattern
    Structural design patterns are ways through which we can describe how classes and objects are composed in an application to form a larger structure. Structural design pattern simplifies the structure of the application by identifying the relationships. It basically focuses on how classes are related to each other via inheritance and how one class is created from other.

    Advantages of Structural design pattern
    • The efficiency of the application increases when we use design pattern
    • Re-usability of the application also increases through the use of structural design pattern
    • Through the use of design pattern in the application, the structure of the application becomes cleaner, simpler interfaces which are easier to understand.

    Below are the different types of structural design pattern
    1. Adapter Pattern
      Adapter pattern is the structural pattern with help of which we can connect two related interfaces together. The interface which joins the two interfaces is known as Adapter.
    2. Bridge Pattern
      Bridge pattern is basically used for separating out the interface from its implementation .Doing this will give flexibility.
    3. Composite Pattern
      Composite pattern is one of the Structural design patterns and is used when we have to represent a part-whole hierarchy. When we need to create a structure, in a way, that the objects are identified correctly. The collection of the object is stored in the class.
    4. Facade Pattern
      Façade Design pattern hides the complexities of the system. A separate interface is used for hiding the complexities of the system and delegate the call to the system classes.
    5. Proxy Pattern
      A class that represents the functionality of another class is a proxy pattern. 

  3.  Behavioral design pattern
    Behavioral patterns are concerned with interaction between different objects. Behavioral pattern not only describes the pattern of objects or classes but also the pattern of communication between different objects. Behavioral pattern basically describes the flow of the process. It is the step by step flow of objects interaction. It maintains how different objects and classes interact with each other to carry out all process.
    Behavioral pattern uses object compositions rather than inheritance .We use behavioral pattern where a single object could not handle the process but which can be handled by group of objects.
    Creational pattern helps in the instantiation of objects. Structural pattern helps in the creation of structure of the application and the behavior of the application will be controlled by behavioral pattern.
    There is different type of the behavioral design pattern:
    • Chain of Responsibility Pattern
    • Command Pattern
    • Interpreter Pattern
    • Mediator Pattern
    • Memento Pattern
    • Observer Pattern
    • State Pattern
    • Strategy Pattern
    • Template Pattern
    • Visitor Pattern
    • Null Object

Advantages of design pattern in software engineering

  • Design pattern allows users to reuse the Software. 
  • Design pattern helps in improving developer communication. 
  • Design pattern captures expert knowledge and widely uses it.

Disadvantages of design pattern in software engineering

  • It is impossible to reuse code of design pattern as it will be complex. 
  • They are validated by experience and discussion. 
  • Memory consumption is more because of generalised format or code without design pattern. 

 Read More:
 Overriding vs. Overloading in OOPs
Types of Polymorphism and advantages
What is a Defect Life Cycle or a Bug life cycle in software testing?
What is software unit testing and why is it important?

Copyright © ianswer4u.com

0 Reactions:

Post a Comment