OOP: Inheritance

One of the main benefits of using Object Orientated Programming is the class feature. I like to think of class objects as a convenient container I can optimize for the situation. For example, in the context of data science you may have several variables you want to keep together or interact with one another. Sometimes it can be a lot easier to create a class object around all of them than it is to work with them separately. Sometimes you will have datasets or objects that are similar at a base level, but also have different unique features. Class inheritance can give you the flexibility of building a parent class to work from, and then build children classes as necessary based on that parent class.

Currency is an example of an object that can have a similar base functionality, but operate differently at a higher level. My Harry Potter project had a base class that handled all the basic necessary functions of currency, but used individual classes for conversion methodology. In my case it mostly just made the code easier to read, but a common example is different species. You can define the base features that most animals share, and then create individual classes for each individual specie or class of specie you want to work with in the code. Another reason inheritance and class objects are so important is that it improve interaction with databases. They allow you to easily maintain the relationships that are represented in the data, and send that data into the database in a logical manner.

Leave a comment

Your email address will not be published. Required fields are marked *