Design Patterns in Golang: The Good, the Bad and the Ugly

Recently I started a series of articles about Gang of Four Design Patterns and their adoption in Golang. They made a lot of noise in the community. I read a lot of contradictionary opionions whether should be used or not. I am publishing those articles as show case how the common design patterns can be adopted and implemented in Golang. I don’t encourage or promote their usage. Every developer has own style of programming, architecture desing and problem solving solutions....

February 3, 2016 · 4 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

Concurrent patterns in Golang: Context

What is concurrency? Concurrent applications have multiple computations executing during overlapping periods of time. Respectively sequential programs in which no computations can be executed in overlapping periods of time. Getting started with Context package The Context package is responsible for signal cancelation and operation deadlines for processes and server requests. The package has an context.Context interface: type Context interface { Deadline() (deadline time.Time, ok bool) Done() <-chan struct{} Err() error Value(key interface{}) interface{} } The interface provides four functions to observe the context state:...

November 29, 2015 · 4 min · Svetlin Ralchev