In every application there is a need in some kind of globally accessible element that all other components can refer to. Configuration, for instance, is one of those important elements. Multiple classes and functions can refer to it at different points in time to base their output on a certain active configuration attribute. A lot … Continue reading Singleton Pattern
Category: Design Patterns
Learn about various design patterns through examples and explanations, and how to apply them in your application
Abstract Factory Pattern
There is a way to generate objects without being tied to concreteness of a certain object. That is called a Factory Pattern or a Factory Method. However, often what happens is that we need to create not one type of an object but several similar ones. Imagine running a restaurant, and needing to have several … Continue reading Abstract Factory Pattern
Factory Pattern
Every time we code something, we create new instances. We literally use word “new” all the time. That creates a concrete object for us. It is bound to a particular type, and we can’t change it after we created it. Every time you use “new” - you create “concrete” instance. This is opposite to what … Continue reading Factory Pattern
Decorator Pattern
We know that if we want to extend functionality of a particular class, we literally “extend” that class and create a subclass. It is one of the ways to do that. However, it is not the most flexible approach. Moreover, you might encounter often the case where subclassing will turn into a nightmare. Imaging you … Continue reading Decorator Pattern
Observer Pattern
There is often a need to develop systems that listen on some kind of event. If you have ever encountered even a bit of Javascript, you saw those onChange, onClick, onKeyUp, and so on. We have a concept of a subject that contains a certain state. Once that state changes, all of the listeners get … Continue reading Observer Pattern
Strategy Pattern
Imagine that you need to create a game where a character is able to fight. Character should be able to pick a weapon. Different weapon would preform different action. We need the character to be able to use his fists, a knife, and a gun. Every weapon can have its own set of attributes and … Continue reading Strategy Pattern
