From Procedural Python to Object Orientation
A look at how to refurbish Python code to use Classes, Attributes, Encapsulation, Inheritance, and Polymorphism
8 min readOct 7, 2020
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:
Both the Computer Shop and the Rebuy Shop offer the following functionality: