Learning By Doing
In my opinion, there's nothing quite like actual projects to really help me learn how to do something. Case in point, I posted last weekend about working on a Python WriteFreely client. I mainly work on it on weekends since, when I finish a day of coding for actual work during the week I usually don't have the motivation to do work on a side project of my own.
While working on it today, I realized that a method in my Post class was actually needed outside of that: check_collection
This method takes the collection passed by the user (think of it like an individual blog, if you're unfamiliar with the API) and validates that it is legitimate. While I initially included this in my Post
class, as I added functionality to retrieve a list of posts I realized I needed it in areas where I wouldn't have all of the information to instantiate the Post
class.
One immediate option was to just make my Post
class more generic so that it could be instantiated and used with less up-front information. However, I didn't particularly like that setup. Instead, I realized that the solution was to simply make a new class, which I called WriteFreely
that would serve as a super class. Then I made my Post
class a subclass of it via:
from client import WriteFreely
class Post(WriteFreely):
In this way, my only change to the Post
class was to delete the check_collection
method which it will now naturally inherit from the WriteFreely
parent class. I've honestly never really done anything with class inheritance before in a real-world scenario, so to me it's just further proof that I'll never get better experience with something than by simply doing it.