Mastery 5: Design Patterns

In software engineering problems will occur sometime, that’s why a design pattern in general is a good solution in software design. 

Using design patterns will make you finish your work in just seconds. How you may ask? Becuase It is magic, you just implement it once and you are done with everything!

https://media.giphy.com/media/12NUbkX6p4xOO4/giphy.gif

 Okay it is not really that simple, but it can for sure speed up the development process by providing tested, proven development paradigms. Efficient software design requires considering problems that may not become noticeable until much later into the project and the implementation phase. By reusing design patterns helps to prevent issues that can cause major errors and at the same time improves code readability for programmers and architects.

As many other topics, design patters can also be divided into different types of design patterns:

Creational design patterns:

These type of design patterns are all about class instantiation and can also be divided into class-creation patterns and object-creation patterns. Some examples:

  • Abstract factory

Provide an open interface for creating families of related or reliant objects without defining their concrete classes. The objects have the responsibility for providing creation services for the entire platform.

  • Builder

Divides the construction of complex object from its representation so that the same construction process can create various representations.

  • Prototype

Acknowledge an abstract base class that specifies a pure virtual “copy” method and maintains a dictionary of all “copies” concrete derived classes. 

Structural design patterns

These design patterns are all about class and object composition. Structural patterns use inheritance to compose interfaces. Patterns define ways to compose objects to obtain new functionality. Some examples:

  • Adapter

Convert the interface of a class into another interface clients expect. The adapter works in the way that it lets classes work together that otherwise couldn’t, because of incompatible interfaces.

  • Bridge

Decouple an abstraction from its implementation so that the two can vary independently. Publish interface in an inheritance hierarchy and bury implementation in its own inheritance hierarchy.

  • Composite

Define an abstract base class that specifies the behaviour that needs to be exercised uniformly across all primitive and composite objects. Subclass the primitive and composite classes of the component class.

Behavioural design patterns

These design patterns are all about class’s objects communication. Behavioural patterns are those patterns that are most specifically concerned with communication between objects. Some examples:

  • Chain of responsibility

The pattern chains the receiving objects together, and then passes any request messages from object to object until it reaches an object capable of handling the message.

  • Command

Command decouples the object that invokes the operation from the one that know how to perform it. To achieve this separation, the designer creates an abstract base class that maps receiver.

  • Interpreter

The interpreter pattern discusses defining a domain language as a simple language grammar, representing domain rules as language sentences, and interpreting these sentences to solve the problem.

References

https://sourcemaking.com/design_patterns

https://refactoring.guru/design-patterns

Lämna en kommentar