Our Blog

Dive into the latest trends, tutorials and insights in computer science. From AI advancements to coding best practices, our blog brings you a wealth of knowledge for tech enthusiasts and developers alike. Stay ahead of the curve with in-depth articles on programming, software development, cybersecurity and more!

Template Method

Template method defines the skeleton of how a certain algorithm could be performed, but defers the implementation of those steps to the children classes. Real world example Suppose we are getting some house built. The steps for building might look like Prepare the base of house Build the walls Add roof A…

Strategy

Strategy pattern allows you to switch the algorithm or strategy based upon the situation. Real world example Consider the example of sorting, we implemented bubble sort but the data started to grow and bubble sort started getting very slow. In order to tackle this we implemented Quick sort. But now a…

Visitor

Visitor pattern lets you add further operations to objects without having to modify them. Real world example Consider someone visiting Dubai. They just need a way (i.e. visa) to enter Dubai. After arrival, they can come and visit any place in Dubai on their own without having to ask for permission or…

Observer

Defines a dependency between objects so that whenever an object changes its state, all its dependents are notified. Real world example A good example would be the job seekers where they subscribe to some job posting site and they are notified whenever there is a matching job opportunity.

Memento

Memento pattern is about capturing and storing the current state of an object in a manner that it can be restored later on in a smooth manner. Real world example Take the example of calculator (i.e. originator), where whenever you perform some calculation the last calculation is saved in memory (i.e.…

Mediator

Mediator pattern adds a third party object (called mediator) to control the interaction between two objects (called colleagues). It helps reduce the coupling between the classes communicating with each other. Because now they don't need to have the knowledge of each other's implementation. R…

Iterator

It presents a way to access the elements of an object without exposing the underlying presentation. Real world example An old radio set will be a good example of iterator, where user could start at some channel and then use next or previous buttons to go through the respective channels. Or take an ex…

Command

Allows you to encapsulate actions in objects. The key idea behind this pattern is to provide the means to decouple client from receiver. Real world example A generic example would be you ordering food at a restaurant. You (i.e.  Client ) ask the waiter (i.e.  Invoker ) to bring some food (i.e.  Command ) a…

Chain of Responsibility

It helps building a chain of objects. Request enters from one end and keeps going from object to object till it finds the suitable handler. Real world example For example, you have three payment methods ( A ,  B  and  C ) setup in your account; each having a different amount in it.  A  has 100 USD,  B  has 300…

Proxy

Using the proxy pattern, a class represents the functionality of another class. Real world example Have you ever used an access card to go through a door? There are multiple options to open that door i.e. it can be opened either using access card or by pressing a button that bypasses the security. Th…

Flyweight

It is used to minimize memory usage or computational expenses by sharing as much as possible with similar objects. Real world example Did you ever have fresh tea from some stall? They often make more than one cup that you demanded and save the rest for any other customer so to save the resources e.g.…

Facade

Facade pattern provides a simplified interface to a complex subsystem.  Real world example How do you turn on the computer? "Hit the power button" you say! That is what you believe because you are using a simple interface that computer provides on the outside, internally it has to do a lot …

Decorator

Decorator pattern lets you dynamically change the behavior of an object at run time by wrapping them in an object of a decorator class. Real world example Imagine you run a car service shop offering multiple services. Now how do you calculate the bill to be charged? You pick one service and dynamical…

Composite

Composite pattern lets clients treat the individual objects in a uniform manner. Real world example Every organization is composed of employees. Each of the employees has the same features i.e. has a salary, has some responsibilities, may or may not report to someone, may or may not have some subordi…

Bridge

Bridge pattern is about preferring composition over inheritance. Implementation details are pushed from a hierarchy to another object with a separate hierarchy. Real world example Consider you have a website with different pages and you are supposed to allow the user to change the theme. What would y…

Adapter

Adapter pattern lets you wrap an otherwise incompatible object in an adapter to make it compatible with another class. Real world example Consider that you have some pictures in your memory card and you need to transfer them to your computer. In order to transfer them you need some kind of adapter th…

Singleton

Ensures that only one object of a particular class is ever created. Real world example There can only be one president of a country at a time. The same president has to be brought to action, whenever duty calls. President here is singleton.

Prototype

Create object based on an existing object through cloning. Real world example Remember dolly? The sheep that was cloned! Lets not get into the details but the key point here is that it is all about cloning

Builder

Allows you to create different flavors of an object while avoiding constructor pollution. Useful when there could be several flavors of an object. Or when there are a lot of steps involved in creation of an object. Real world example Imagine you are at Hardee's and you order a specific deal, lets…

Abstract Factory

A factory of factories; a factory that groups the individual but related/dependent factories together without specifying their concrete classes. Real world example Extending our door example from Simple Factory. Based on your needs you might get a wooden door from a wooden door shop, iron door from a…

Categories
Archive