
In this article, we will explore the object-oriented programming (oops’s) concept — Classes and Objects in python by implementing in-gear design calculation. In the previous article, we explored the python libraries for gear design (link). In this article, we will understand how mechanical industries can utilize the oops concept for complex and time-consuming projects to improve work -reduce labor and time.
Let’s have a brief introduction to object-oriented programming(OOP).

OOPs: In programming, generally, we solve problems by creating an object, which means a group of variables and functions. These variables are referred to as a property of the objects and process as the thing’s behavior. The method is called an object-oriented program; once we create an object, we can reuse the program many times and in many ways. Let’s understand in more detail with the below example.
OOPs concepts with Real Time Examples: Consider the Automotive gear. There are many different types of equipment with different terminology, but there will be some same essential characteristics, price or speed, and applications.
Class: Class is a blueprint, template, prototype, or logical construct of an object

Object: Using the above template or blueprint of the Gear class, we can create any gear in real. Many companies make their bags — spur, helical, warm, rack, pinion, etc.- e, model, speed, but the values and brand can differ.

Let’s get into the problem statement along with coding the part.
Problem statement :
Consider a spur gear with 22 teeth with a diametral pitch of 4 inches. Calculate diametral pitch.
Given : Tooth number (N) = 22, Diametral pitch (pd) = 4.
- Spur gear : Diametral pitch (d) : d = N//pd.

Class: Spur gear.
Object: Diametral pitch.
Attributes: Tooth count, pitch diameter.
Methods: training, playing
As per the code step1, we have created a Spur gear class- a basic template for different gears. Step2 needs to define the constructor – it is nothing but a particular function to describe an initial requirement using __init__, and to create any part inside a class needs to mention the self keyword to connect the attribute with its value. In step 3, we created an Object to assign the attribute value and then called the method to get the output.
Ok, let’s reuse the same code for helical gear.
2. Helical gear : Pitch diameter (d) : d = N//pd*cos alfa.

Here, all the steps are the same; only while inheriting the class mention the spur gear class in the bracket and update the constructor as we reuse the code no need to mention all the attributes; call the spur gear constructor, and here we need to add the helical angle as per the formula, for that add attributes separately by using init and self to get helical Diametral pitch. This is how we can use this concept for all gear designs.
So hopefully, we got a good knowledge of how classes and objects are created and how to reuse the class.
Since the OOP concept is huge and I don’t want to overload all things in the same article; however, it is a very good start to OOP implementaiton. We will cover in-depth details of polymorphism and inheritance in upcoming articles.
Happy coding.
For more mechanical + programming insights, follow me on LinkedIn
https://www.linkedin.com/in/radhika-manjunath
Thanks & Regards
Radhika Manjunath
