Class Attributes
Learn the difference between instance attributes and class attributes.
Great work so far!
Our users can now create and interact with posts effortlessly, but there’s a key issue we need to address: tracking the total number of posts and users. Currently, while we’ve created User
and Post
objects, each of these objects is self-contained. This means that they don’t share statistical information across all instances, and we have no easy way to know how many posts have been made or how many users have joined the platform.
The problem is that there is no centralized way to share this kind of information across instances.
But before that, we need our code to look better, be easier to read, and be easy to understand. Let's do that!
Organizing our project
So far, we’ve written all our code in one file. While that’s perfect for learning small examples, real-world projects benefit greatly from a modular design. Organizing your code into separate files has several advantages:
Maintainability: Each class lives in its own file, making it easier to locate, modify, and debug code.
Reusability: Modules can be imported into other projects.
Collaboration: In larger teams, different developers can work on different modules simultaneously.
Organization: A clean file structure helps you manage and scale your project.
Now, let’s see how we can structure our Chirpy project.
Get hands-on with 1400+ tech skills courses.