A GUIDE TO SOFTWARE DESIGN PATTERNS

Image for post
Image for post
Photo by JESHOOTS.COM on Unsplash

The strategy pattern enables algorithms to switch at runtime. In plain English, that simply means deciding at runtime which concrete implementation of an interface to use using a context, which is where the actual concrete implementation injection happens. Deferring the decision on which algorithm to use until runtime allows more flexibility, reusability. It also makes the codebase more maintainable

This pattern comes in handy when multiple algorithms for a given strategy (interface) is needed. including the client, implementation of this pattern requires four components:

  1. Client -> where the context gets used
  2. Context -> where an algorithm is selected at runtime
  3. Strategy ->…


A Guide to Software Design Patterns

Image for post
Image for post
Photo by Justin Lawrence on Unsplash

The word facade borrowed from the French language (façade) and translates to “face” or “front of”. It’s commonly used to refer to a building structure. For instance, the facade of a building. You don’t get much information about a building just by looking at its facade.

A facade design pattern is an object that plays the role of a front-facing interface that hides the more complex underlying structure of some code. This pattern should be used when complex functionalities need to be hidden behind a single and simplified interface or as a launching point for a tightly-coupled system.

What!!! Do people actually choose to build tightly-coupled systems? Yes, they do. Sometimes, it might be necessary for very specific business cases. Most developers at some point in their career has worked or will work on some monolithic application.


A guide to software design patterns

Image for post
Image for post
Photo by Kamil S on Unsplash

The decorator pattern, one of the seven structural patterns, allows behavior to be added to an individual object, dynamically, without modifying the behavior of other objects from the same class.

The implementation of this pattern is also a good example of the single responsibility principle (S) of the S.O.L.I.D principles. It’s also very similar to the Chain Of Responsibility pattern with one major difference. In this pattern, all the classes handle the request while only one class handles the request in the chain of responsibility.

I’ve always found it easier to understand any new concept with a real-world scenario. …


Image for post
Image for post
Photo by Andrea Piacquadio on Pexels

Working From Home (a.k.a WFH ) has been something that only a few industries ( e.g IT, Sales, etc..) allowed or favored. It used to be viewed as a privilege for some. I’ve worked fully remote jobs and jobs that allow WFH on a need only basis. I became a dad two and a half years ago and have an overly-friendly-want-to-say-hi-to-everybody child that almost makes working from home impossible at times. I’ve learned a few things that helped me make the most of WFH with kids.

Inform your colleagues you have kids

This might sound trivial, but it is very important. Informing your peers that you have kids prepare them in some ways for the unexpected outburst of that wonderful sound of laughter, which at times can be annoying for some. If you jump on audio/video calls, which you will do often now more than ever, now and then your kids might pop up. Whoever is on the other end of that call, won’t be as surprised or even get distracted when it happens. …


A guide to software design patterns

Image for post
Image for post
Photo by Aditya Joshi on Unsplash

The proxy pattern, one of the seven structural patterns, is pretty much a class that represents another class. In plain English, a proxy is a wrapper class that provides the same and sometimes additional functionalities on top of the real object itself. The primary purpose of the proxy pattern is to control access to the real object.

When you call your phone service provider, for example, you usually speak to a proxy — i.e. a representative of the company. Chances are you will need to provide some kind of identifiable information, otherwise, you won’t be serviced. Your identity has nothing to do with the available services, it only determines if you are indeed a customer and allows you access to those services if you are eligible. The role of the representative (proxy) is to make sure you are a legitimate customer.


Image for post
Image for post
Photo by Levi Jones on Unsplash

I was asked to explain the difference between a Stack and a Queue earlier in my career. It’s a pretty straightforward question, I’ll share my explanation and provide a code sample for each.

Stack

A stack is simply a Last In First Out(LIFO) non-generic collection of objects. In plain English, that means the objects in the stack are ordered and can only be accessed by the most recently added.

Good visual representations of a stack can be seen all over. When you go to a grocery store, for instance. You might see pallets of cases of water or some type of liquid. …


A guide to software design patterns

Image for post
Image for post
Photo by Joshua Rawson-Harris on Unsplash

The Memento pattern is one of the eleven behavioral design patterns. Memento pattern is used to restore an object to its previous state. It is also known as a snapshot pattern. This is simply a way of tracking states of an object and having the ability to revert previous changes.

Implementing this pattern requires three objects:

  • originator
  • memento
  • caretaker

The originator is the object we’ll be making changes to. It provides a way to create and restore mementos.

The memento is a snapshot of the originator at some point in time. Mementos can only be created and read by the originator and cannot be changed once created — i.e. …


A guide to software design patterns

Image for post
Image for post
Photo by Fabian Grohs on Unsplash

The state pattern is one of the eleven current behavioral software design patterns. It allows an object to change its behavior when its internal state changes. This pattern makes it easy to change an object’s behavior without having to check the current of the object with a conditional statement, which makes a codebase flexible, testable and maintainable.

Pattern Ideal Usage

When should this pattern be used? Let’s say you’re in charge of designing a system that changes the input of an audio device. There are multiple inputs we can change to but the switch happens in sequential order ( e.g. Bluetooth, Optical, Coaxial, RCA and USB). …


A guide to software design patterns

Image for post
Image for post
Photo by Miltiadis Fragkidis on Unsplash

The chain of responsibility pattern is a design pattern consisting of a source of command objects and a series of processing objects.

This simply means that each object in the chain behaves as an object-oriented version of an if-condition. When a request comes in the chain, if it cannot be handled by the first object, it gets passed on to the next object and so forth until it’s handled or rejected if no object can handle it.

Each object contains specific logic on what level or type of request they can handle. Each object must have a way to add the next processing object to the chain. …


Image for post
Image for post
Photo by Sharon McCutcheon on Unsplash

Curiosity

A few months ago I didn’t even know you can make money writing on medium. A colleague and I were talking and she mentioned to me she just published a few articles and would like me to read them. She sent me the links and they were good. I’ve always liked sharing knowledge, so she figured I would enjoy writing and suggested I look into writing as well.

In the next few days, I researched the process a bit and found it to be easy and straightforward, however, I didn’t write any article right away. My intention wasn’t to make money, but rather sharing my knowledge with whoever could benefit from it. …

About

Petey

Husband, father, engineer, musician, and writer by luck. I write mostly about whatever comes to mind. Follow me on this crazy writing journey if you dare.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store