Designing Modules in Python [ebook]

Designing Modules in Python is part of HashedIn’s training program for junior developers to get better at design. Today, we are making it available as a free ebook.

Download E-Book

Who is this ebook for?

This book is for all those who have some experience in an object oriented programming language. If you wish to get better at the module or class level design, then this book is definitely for you. You will be able to identify a good design from the bad after you finish reading this book

All throughout this book, python is used to introduce various design patterns. However, the knowledge of python is not mandatory. If you can understand classes and methods, you will easily be able to understand the contents in this book

How to use this book

To make the most of this book, read the requirements at the start of each chapter and write down your solution. Then read through the rest of the chapter and critique your solution.

Good design is obvious once presented. However, arriving at that solution is difficult, especially if you are new to programming. Writing down your solution is the only way to realize the shortcomings of your design. If you read the chapter without writing, you will tell yourself “That was obvious. I would have solved it in a similar manner”

History of this book

At HashedIn, we conduct a training program for junior developers to get better at design. During one of these programs, we asked developers to design a module to send sms/text messages. We also asked them to call the sms module from 3 different client applications. They had 30 minutes to complete this activity.

After 30 minutes, we revealed a new set of requirements. Additionally, we set 2 hard rules for them to implement these requirements:

  1. Developers were not allowed to change the way client applications invoked their sms module
  2. Developers were not allowed to modify existing code. Instead, they had to write new code to address the additional requirements, without duplicating code.

20 minutes later, we again introduced a new set of requirements. And after another 20 minutes, we introduced the final set of requirements.

Initially, developers felt the problem was very simple. They were at loss to understand why design was even needed. Isn’t this a simple python function?

But as new requirements emerged, and because we gave them constraints (don’t change existing code) - they began to appreciate the various design principles. Some even developed a mental model to discern good design from bad.

Over time, we got the opportunity to review designs from several developers. We learnt how junior developers think when asked to solve a problem. Based on these patterns, we wrote a series of blogs on how to design modules in python.

Design Modules in Python

Python Interface Design - Designing Modules Part - 1

This is the first part of the 5 part python blog series. This blog will teach you as to how you can design a reusable python module. By the end of the post, you will get a great understanding of writing reusable and extensible modules in python. Read More

Python Dependency Injection - Designing Module Part-2

The Part 2 of the 5 part python series discusses about the dependency injection in Python. You will learn as to how python design patterns can be benefited from dependency injection. Read More

Exception Handling In Python - Designing Modules Part - 3

Now that you have successfully completed the first 2 parts of the design patterns in python, it is now time for us to continue with the part 3. In the previous posts, you learnt how to create the interface of the module. This post will have a detailed discussion on the Exception Handling in Python. Read More

Open Closed Principle in Python - Designing Modules Part - 4

This module of the python blog series is about the Open closed principle. In the earlier posts, you learnt on how to create the interface for the module and then worked on its implementation. The open/closed principle teaches us not to modify our already working code just for adding new features. Read More

Inheritance versus Composition in Python - Designing Modules Part - 5

Congratulations! You are now about to read the final part of the Python series. In the previous posts, you learnt on how to create interface of the module, worked on the implementation and added the retry mechanism. In this post we will be comparing the inheritance and composition to determine better ways to reuse the existing code. Read More

Download E-Book

Like what you read? Share this blog on:

Are You Geared For Tomorrow?

Look Ahead