Introduction

Template method pattern is one of the behavioral design patterns. I think that you all must have already used this pattern many times.

In this pattern, Abstract class holds the primitive operations which needs to be executed and all those methods might be abstract if they are customizable and it also holds one method which executes all the other methods in pattern which you have defined. This method is also called template method. This abstract class must be overridden by sub classes to write custom primitive operations according to your requirements.

We can understand this pattern by following code.


Command pattern is a behavioral design pattern in which the object is encapsulate all the information to be executed at later time.

To understand this pattern let’s take an example of signing up for an account.

So let’s assume that registration is three step procedure. First step is to fill basic details, second step to fill business details and then final step to fill payment details. Initially object of Command is created and will be used to collect all information. …


Let’s understand behavioral design pattern before we start on observer pattern.

Behavioral design pattern

This type of design patterns will help you to solve problems related to behavior of your program. This patterns are concerned about interactivity between objects and the responsibility of objects and yet they must be loosely coupled to each other.

Observer pattern is one of this type of design pattern which we will understand in this story.

Observer pattern

In this design pattern, The object maintains the list of observers which are dependent on it. So whenever something gets changed in that object, it will notify to all observers in the…


Introduction

In most cases, We use Django Rest Framework filtering module to filter data but if you have large dataset then in those cases we must need indexing engine to index data and then do filtering on them. There are many search indexing engines out there. In this article we will use one of them and will understand how that can be used in Django project along with Django Rest Framework.

All index engines are differently implemented and to use them in python they are providing interfaces. …


In this tutorial, you will learn about deployment on Ubuntu desktop or Ubuntu server using following technologies

Setup new or existing project

To start new project, create virtual environment using following commands. You can create virtual environment wherever you want but I would suggest to create parallel to you project folder. (For existing project)

sudo apt install python-virtualenv 
Virtualenv -p python3 venv
source venv/bin/activate

Install django to start new project in Django

pip install django==2.1

Start new project with name “demo”

django-admin startproject demo

Change directory to your project folder and install all the python dependencies (For existing project)

cd demo
pip install -r requirements.txt


Django 2.0+ is the big change against 1.x versions of Django. In new version, Few functionalities are changed. For changes look at the official release note. It supports Python 3.4+. Django 1.11 was the last version to support Python 2.7.

Before creating new project we must create one python virtual environment to make separate development environment for the project.

Create Python virtual environment with name venv. To do that follow this tutorial - setup-python-virtual-environment.

Activate Python virtual environment venv

source venv/bin/activate

Now as this Python virtual environment is separate to work on the project so we can install the python…


This SingleTon pattern is very useful pattern when we need global instance of any service or class. This pattern is used to implement a class which returns only one instance every time when we try to create new instance.

Pattern Type — Creational Design Pattern

Benefits -

  • One and only one object is created
  • Object with global access to whole program
  • Controlling concurrent access to shared resources.

Now to implement this pattern to achieve SingleTon instance, we have 4 solutions and all of them are explained below one by one so, you can use any of them according to your…


Introduction

Proxy design patterns fall under structural design patterns category. It basically provides interface to real object which can be of different types such as networking, large in memory, file etc. Proxy class acts as intermediate to requester and provider. In serving web requests, proxy server is the best example for this pattern. When any new request comes to proxy server, it will evaluate the request and then will forward request to appropriate server and get response to give back to requester. This proxy server also provides additional security and other functionalities.

Proxy pattern can be used in following scenarios -

  • When complex system is built, it would be helpful…


Facade pattern allows to hide complexity of system and provide simple interface to client of the service.

Before going through programming example, let’s understand a real life example, Shopkeeper. In shopkeeper, Many items are available but custom doesn’t know the exact location of the item in the store so we ask shopkeeper with list of items and shopkeeper provides all the items which customer wants to buy as shopkeeper know where items are located. Shopkeeper is facade of the shop.

Another easy example is facebook-sdk library to user facebook APIs. It provides very easy and simple methods to access all…


Factory is a creational design pattern which helps hiding object creation process.

Pattern Type — Creational

Benefits -

  • Object creation can be independent of the class implementation.
  • Adding support of new type of object is very easy
  • Logic of object creation is hidden

Type of patterns

  • Simple Factory pattern: This design allows to create objects without exposing the object creation logic.
  • Factory method pattern: This design allows to create objects, but defers the decision to the subclasses to determine the class for object creation.
  • Abstract Factory pattern: An Abstract Factory is an interface to create related objects without specifying/exposing their classes. …

Hardik Patel

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