From Procedural Python to Object Orientation

A look at how to refurbish Python code to use Classes, Attributes, Encapsulation, Inheritance, and Polymorphism

Sami Islam
8 min readOct 7, 2020
Photo by ian dooley on Unsplash

In this article, I am going to go through some procedural code in Python and update that to Object-Oriented code using Classes, Attributes, Encapsulation, Inheritance, and Polymorphism.

I use Visual Studio Code with the pipenv Python package manager, Python v3.8.2, and the compile-time static type checker mypy. You can find more about this setup in my article:

Let’s get started!

Procedural code

There are two hypothetical shops: The Computer Shop and The Rebuy Shop. The following code shows how they are being used:

The procedural code for the shops using a computer
The procedural code for the shops using a computer

Both the Computer Shop and the Rebuy Shop offer the following functionality:

--

--