Head First into Design Patterns

Danin Sudjono
PDB+R
Published in
3 min readMay 20, 2019

Hello everyone. It’s Danin again, and today I’m going to talk about refactoring and design patterns. These two topics are some of the few main topics students study in the Advanced Programming course, Faculty of Computer Science, University of Indonesia. It expands on the foundations they have learned during the previous courses.

The book we use for Advanced Programming course

Design Patterns

According to the Head First Design Patterns book (which is an absolutely good read, I recommend) someone has already solved your problems. Yeah, no kidding. Design problems have been a thing since the old ages of coding, and the solution to that is Design Patterns.

Simply put, design patterns are concepts or solutions to underlying problems in code, designed to be reusable and fitted to many recurring problems. Design patterns help software development by fixing code and allowing the code to be reusable.

There are many types of design patterns, but we can classify them all into three main categories:

  • Structural Design Patterns. Mainly focuses on how classes and objects are composed in a class.
  • Behavioral Design Patterns. Mainly focuses on how objects do things.
  • Creational Design Patterns. Mainly focuses on the creation of objects and classes.

Refactoring

To refactor means to change code without changing what it does. The change we are talking about could be clarification, simplification, or some other thing. In agile programming, refactoring is important because we want to keep our code maintainable. No matter how strong the code, it will rot in time. New dependencies, new coding techniques, and more advanced technology will always be available as time passes.

Our Implementation

For design patterns, we have a few implementations. First, Django uses the Model-View-Controller design pattern for its workspace. Usually used for web-based applications, as we can separate the major components and reuse.

Model: models.py

Views: template

Controller: views.py

We have also implemented refactoring as a part of our daily commits. One of the recent things we had to refactor was a use-case that handled term creation. At first, we could input the term name and so on, but apparently that should not be the case. We changed it so that now the term is created automatically.

Before
After

Refactoring and design patterns help in making better and reusable code. There are many more implementations of design patterns out there (seriously, read the book), and different problems require different solutions. I hope to be able to implement a lot more refactoring and design patterns in the future.

That’s it from me for now. Hope you learned something from this. Until next time.

--

--