Desing Patterns in Golang: Bridge

Introduction The Bridge Pattern is a creational design pattern used to decouple an abstraction from its implementation. The bridge uses encapsulation, aggregation, and can use inheritance to separate responsibilities into different classes. Purpose Decouple an abstraction from its implementation that allows both to vary independently. Publish interface in an inheritance hierarchy, and bury implementation in its own inheritance hierarchy. Design Pattern Diagram The objects participating in this pattern are presented on the following diagram:...

March 17, 2016 · 3 min · Svetlin Ralchev

Design Patterns in Golang: Prototype

Preface The Prototype Pattern creates duplicate objects while keeping performance in mind. It’s a part of the creational patterns and provides one of the best ways to create an object. In the mainstream languages (like C# and JAVA), it requires implementing a prototype interface which tells to create a clone of the current object. It is used when creation of object directly is costly. For instance, an object is to be created after a costly database operation....

February 6, 2016 · 5 min · Svetlin Ralchev

Desing Patterns in Golang: Factory Method

Introduction The Factory Method pattern is a design pattern used to define a runtime interface for creating an object. It’s called a factory because it creates various types of objects without necessarily knowing what kind of object it creates or how to create it. Purpose Allows the sub-classes to choose the type of objects to create at runtime It provides a simple way of extending the family of objects with minor changes in application code....

January 31, 2016 · 4 min · Svetlin Ralchev

Desing Patterns in Golang: Builder

Introduction The Builder Pattern is a creational design pattern that’s used to encapsulate the construction logic for an object. It is often used when the construction process of an object is complex. The patterns is well suited for constructing different representations of the same class. Purpose Separate the construction of a complex object from its representation so that the same construction process can create different representations. A common software creational design pattern that’s used to encapsulate the construction logic for an object....

January 24, 2016 · 4 min · Svetlin Ralchev

Design Patterns in Golang: Singleton

Introduction Sometimes it’s important to have only one instance of an struct. This is useful when exactly one object is needed to coordinate actions across the system. Singletons provide a global point of access to themselves. The singleton pattern is one of the simplest design patterns. It requires only one type which is responsible to instantiate itself, to make sure it creates not more than one instance. The same instance can be used from everywhere....

January 17, 2016 · 3 min · Svetlin Ralchev