Fall 2026
  • Discord
  • Gradescope
  • Syllabus

On this page

  • Start
  • A Branch for the Feature
  • Starting Data
  • An Account to Follow
  • A Post to Like
  • Readable Accounts and Posts
  • An Announcement in the Feed
  • Check the Feed
  • The Class Design
  • Share the Feature
  • Submit
  • Grading Rubric

Lab: Objects and Collaboration

Due: Wednesday, October 28 at 11:59pm · Worth: 6 points

Build the accounts and posts for a small social feed, then share the change in a pull request. Users need followers; posts need likes, hashtags, and readable text. The classes earn all 6 points, with each constructor and method checked independently. The feed rehearsal and pull request are ungraded practice.

Start

Create lab-objects from the starter template, clone your copy, and open it in VS Code. A starter ZIP is also available; follow the first lab’s repository workflow if you need help publishing it.

A Branch for the Feature

After publishing the initial commit, create a branch for your implementation:

$ git switch -c implement-classes

Open lab_classes.py and feed_rehearsal.py. The first holds the methods to complete; the second shows how the feed will call them.

Starting Data

Each new account or post needs its own initial state. The reading’s constructor example shows how __init__ stores values on self, the instance Python is creating.

Meme: a British developer shown a Python constructor for the first time, captioned 'that is an __init__, innit?'

An Account to Follow

Complete User in lab_classes.py:

Check a sequence of two follows and one unfollow: it should leave one follower. Then unfollow twice more. What should the count be? Create a second user and confirm that changing the first user’s count leaves the second unchanged. The reading covers methods that change an instance.

A Post to Like

Complete Tweet:

Use string operations from the earlier labs. For example, the starter’s doctests check behavior like this:

>>> Tweet('alice', 'learning #python and #oop #python').hashtags()
['python', 'oop', 'python']
>>> Tweet('bob', 'just a normal tweet').hashtags()
[]

Readable Accounts and Posts

Implement __str__ so an account displays as '@alice' and a post as '@alice: hello world'. Return the formatted string from the method.

Implement User.__eq__ so users with the same username compare equal, regardless of their follower counts; different usernames compare unequal. The same account loaded twice from a database should still compare equal. See the reading on dunder methods, which define behavior for operations such as print and ==.

An Announcement in the Feed

The rehearsal includes an Announcement as well as a Tweet. Find its show(post) function and identify the attribute both objects must provide. Neither class needs to inherit from the other. This is duck typing: the function uses the operations its argument supports.

Duck typing meme: if it has a .text, prints like it has a .text, and quacks like it has a .text, Python calls it a tweet and gets on with its day.

Check the Feed

Run the doctests after each method, then try the supplied feed:

$ python -m doctest lab_classes.py
$ python feed_rehearsal.py

No doctest output means the published examples pass; Gradescope also checks new inputs. The rehearsal should show @alice, counters that stop at zero, and ['python', 'games', 'python'] as the game-night post’s hashtags. Its final two messages should be the tweet and the announcement.

If a method is unfinished, the rehearsal reports the exception and continues. Use that message or an unexpected result to find the method that needs work, then rerun its doctests.

The Class Design

Each class groups data with operations that use it: followers belong to a user, likes to a tweet. A standalone function can handle work that does not need that shared state. Edsger Dijkstra had stronger objections to OOP:

Meme of Edsger Dijkstra captioned with his line that object-oriented programming is an exceptionally bad idea which could only have originated in California.

Share the Feature

Commit and sync your branch, then open a pull request from implement-classes into main in your own repository. Describe one method and how you tested it, read the diff, and discuss it with a classmate if available before merging. You may submit the working branch before merging; the pull request, review, and merge earn no separate points. For more practice, see the branching and merge-conflict tutorial.

Submit

Commit and sync lab_classes.py, then use Gradescope’s GitHub option to submit your lab-objects repository and the branch containing your work to lab-objects. You may resubmit as you complete more methods.

Grading Rubric

Gradescope checks each item separately and adds the points earned.

Total: 6 points.