PPL2021 — Design Pattern & Refactoring — Why Pattern Could ImproveYour Development Cycle

Photo by Silvio Kundt on Unsplash

“Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice” [Christopher Alexander, A pattern language, 1997.]

Have you ever realise that pattern is embedded in our daily life. For example, your sleep pattern, you slept at 10.00 PM and woke up at 05.00 AM. You feel that pattern work for you because you have to go to work at 07.00 AM, and you arrived at home at 06.00 PM and need to do some relaxing and other things. And also, your daily pattern could be adapted by other people with the same schedule and responsibilities as you. In this article, we will discuss how design pattern could be applied to your code. Applying tested and proven pattern could shorten your development time and also guaranteed that solution will always work.

What is Design Pattern?

According to Gamma, Object-Oriented design is hard, designing a reusable Object-Oriented design is even harder. Every time you found an obstacle in your code, it will be harder to design a new solution rather than using an existing solution that has been proven to work before.

Benefits of Design Pattern

According to Pittsburg University, the benefit of Design Pattern is:

  • Patterns will capture expert knowledge and design tradeoffs to make this knowledge widely available.
  • Patterns will enhance understanding of software by documenting the architecture of a system.
  • Design pattern enables large-scale reuse of software architectures.

Categories of Design Pattern

According to reference book about design pattern there is 23 design pattern which can be categorised into three categories, there are :

Design Pattern in Django


HttpRequest Implementation in Django
Signals implementation in Django
Template implementation in Django
Django Models for Database
Django Views for Controller
Django Templates for view
Django MTV Implementation

Refactor in Django

Now that we know what the Django pattern is. I will discuss shortly about refactoring and its importance when implementing your code. The basic idea of refactoring is you can’t always write your code perfectly for the first time. In your first implementation, you may write unused variables, random variables naming, importing unused package, and so many more. Because as we know that Django uses abstraction, listener, template patterns. We can always make sure that we can change our implementation later without worrying our new implementation will break our initial code. An example of refactoring in my project can be seen below :

Refactoring in My Project

Under-graduated Students Majoring in Computer Science