Inheritance—Creating a VerifiedUser
Explore inheritance in Python by building a VerifiedUser subclass that inherits from User, adds verification badges, and custom methods. Understand how to extend functionality cleanly without altering the parent class. Practice applying super() to initialize inherited attributes and prepare for advanced user role customizations.
We'll cover the following...
Right now, all users on Chirpy are the same—whether they are regular users or verified ones. But just like in real-world social networks, some users need to stand out. Verified users bring credibility and recognition to the platform, making their presence more distinct.
To reflect this, Chirpy also recognizes verified users, giving them:
A verification badge to indicate their authenticity.
Special privileges—perhaps their posts appear more prominently.
Now, we could solve this problem by adding an extra attribute like is_verified to our User class, but this approach comes with some major drawbacks.
Take a moment to reflect: What potential drawbacks might arise from this approach? Jot down your ideas in the widget below.
Clearly, we need a better way to structure our code so that verified users can have their own unique attributes and behaviors without affecting regular users. ...