Search⌘ K
AI Features

Methods in SocialNetwork

Explore how to build management methods in a Python SocialNetwork class to handle users and posts effectively. Understand method design for searching, adding, and removing users while ensuring username uniqueness. Discover how composition supports scalability and maintainability in OOP projects.

In our last lesson, we built a SocialNetwork class that simply stored Users and Posts. Now, let’s take our design further by giving SocialNetwork the ability to manage these objects.

Imagine a bustling city where thousands of people live and interact. Without a mayor or city planner, chaos would reign! Similarly, our SocialNetwork class isn’t just a passive container—it’s the mayor of Chirpy, actively managing users and posts to keep the platform organized.

You’re tasked with designing the SocialNetwork class for Chirpy, which must empower the platform with the following features:

  • Search for users: Allow the system to locate a user by their username.

  • Ensure unique usernames: Prevent duplicate usernames from ...