Categories: Design Pattern

Design Patterns – Introduction

A design pattern is a general reusable solution for the common problems in software engineering design. The pattern shows the relationships and the interactions between the classes or the objects. This idea can increase the development process speed by providing a well-tested development paradigm or design paradigm. Design patterns and programming languages are independent. The design pattern is a kind of strategy for solving common problems. It means the design pattern is a kind of idea or concept and isn’t the particular implementation. It uses the project design pattern to make the project code more flexible, reusable, and maintainable.

Remember a thing that isn’t always to implement design patterns in the project. Design pattern doesn’t mean the project development. Design pattern means for the common problem – solving. Using the design pattern on the project represents the suitable pattern that avoids such issues in the future. No, anyone pattern uses for good in any situation.

Types of Design Patterns

The design pattern can sort of three main types, such as the “Creational Patterns,” the “Structural Patterns,” and the “Behavioral Patterns.”

Creational Patterns:

The creational patterns are about class instantiation and object creation. It can further classify into Class-creation patterns and object-creation patterns. The class-creation patterns use the inheritance methods in the instantiation process. The object-creation patterns use delegation ways to get the task done. The creational designs have more ways to implement, such as the Factory Method, Abstract Factory, Builder, Singleton, Object Pool, and Prototype.

  • Abstract FactoryCreate an instance of several families of classes
  • Builder Separates object construction from its representation
  • Factory MethodCreates an instance of several derived classes
  • Object PoolAvoid expensive acquisition and release of resources by recycling objects that are no longer in use
  • PrototypeA fully initialized instance to be copied or cloned
  • SingletonA class of which only a single instance can exist

From source making

Usage occasion – Creational Patterns

1) Suppose the developer wants to create the database connection class files to connect multiple databases at multiple locations. Basically, in a single database, a developer will create the single instance of the database connection class, which uses to apply all of the database operations wherever required. Suppose the developers want to make the database connection class to connect multiple databases. In that case, the developer will create numerous database connection class to separate connection to the database. To deal with this situation, the developer can make only one database connection instance for a single connection established by programs. This way can easily manage the database connection instance via a single instance and control the load balance, unnecessary connections, etc.

2) Suppose the developer wants to create multiple similar instances and wants to do the loose coupling. This situation can choose the Factory pattern strategy. A factory pattern class builds the conversation bridge between numerous classes. If the developers are developing an application using the database or the third-party tools as the back-end, but in the future need to change the database or the third-party tools, the developers will need to modify all code. The factory design patterns maintain loose coupling and quickly implement. The developer should choose it to achieve loose coupling and create a similar object.

Structural Patterns:

The structural patterns mean that organize different classes and objects that structure larger structures and then provide the new functionality. The structural patterns have more ways to implement, such as Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Private Class Data, and Proxy.

  • AdapterMatch interfaces of different classes
  • BridgeSeparates an object’s interface from its implementation
  • Composite A tree structure of simple and composite objects
  • DecoratorAdd responsibilities to objects dynamically
  • FacadeA single class that represents an entire subsystem
  • FlyweightA fine-grained instance used for efficient sharing
  • Private Class DataRestricts accessor / mutator access
  • ProxyAn object representing another object

From source making

Usage occasion – Structural Patterns

1) Suppose the developer creates two interfaces that are incompatible with each other. Hopefully, these interfaces can establish a relationship made by the adapter mechanism. Its calls an adapter design pattern. The adapter design pattern can convert the interface class to another interface class or class that is the client-side expects. The interface class or class can’t work together because of incompatibility. However, the adapter can help the developer solves this problem.

Behavioral Patterns:

The behavioral patterns are about identifying the common communication patterns between objects and bring about these patterns. The behavioral patterns have more ways to implement, such as Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Null Object, Observer, State, Strategy, Template method, and Visitor.

  • Chain of ResponsibilityA way of passing request between a chain objects
  • CommandEncapsulate a command request as an object
  • InterpreterA way to include language elements in a program
  • IteratorSequentially access the elements of a collection
  • MediatorDefines simplified communication between classes
  • MementoCapture and restore an object’s internal state
  • Null ObjectDesigned to act as a default value of an object
  • ObserverA way of notifying change to a number of classes
  • StateAlter an object’s behavior when its state changes
  • StrategyEncapsulates an algorithm inside a class
  • Template methodDefer the exact steps of an algorithm to a sub-class
  • VisitorDefines a new operation to a class without change

From source making

Usage occasion – Behavioral Patterns

Template pattern means that is kind of delay the algorithm in operation deferring some steps to sub-class. The template method means that lets subclass redefines the action of the algorithm without changing the algorithm structure.

Reference

davidsky69

View Comments

Recent Posts

API Gateway in .NET 5 with Ocelot

What is the API gateway? An API gateway is an API management tool that sits…

3 years ago

.NET 5 application with Onion architecture

The .NET 5 SDK is a kind of milestone in the .NET world. The .NET…

3 years ago

SOLID Principles – Dependency inversion principle

In object-oriented design, the dependency inversion principle is a specific methodology for loosely coupling software…

4 years ago

SOLID Principles – Interface segregation principle

In the field of software engineering, the interface segregation principle (ISP) states that no code…

4 years ago

SOLID Principles – Liskov substitution principle

Subtype Requirement: Let  be a property provable about objects  of type T. Then  should be true for objects  of type S where S is…

4 years ago

SOLID Principles – Open-closed principle

In object-oriented programming, the open–closed principle states "software entities (classes, modules, functions, etc.) should be…

4 years ago