FAQ: Object-Oriented Programming - Review

This community-built FAQ covers the “Review” exercise from the lesson “Object-Oriented Programming”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Intermediate Python 3

FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Up to this point in the course there has only been one short video on decorators and then the exercise on @abstractmethod. In this review suddenly the @property and @username.setter decorators appear out of no where. It is very frustrating when content comes up in a review that has not been covered in the lessons. After some research (on another site), it appears these special decorators are very useful to mastering OOP, so I wonder why they have not been covered, yet appear in the review? It would be great if this course was amended so that they are included.

edit: I see now that the property decorator is covered in the section following the review and the project. Perhaps consider moving this section to before the review/project. The fact I went to a different site to look it up thinking id missed something is evidence enough the order needs changing!


What is the purpose of the following piece of code encapsulated in the AbstractEmployee class?

  def say_id(self):

Why wouldn’t you just add a new say_id method to the other classes / sub classes as neccesary?

from abc import ABC, abstractmethod

class AbstractEmployee(ABC):
  new_id = 1
  def __init__(self):
    self.id = AbstractEmployee.new_id
    AbstractEmployee.new_id += 1

  def say_id(self):

class User:
  def __init__(self):
    self._username = None

  def username(self):
    return self._username

  def username(self, new_name):
    self._username = new_name

class Meeting:
  def __init__(self):
    self.attendees = []
  def __add__(self, employee):
    print("{} added.".format(employee.username))

  def __len__(self):
    return len(self.attendees)

class Employee(AbstractEmployee, User):
    def __init__(self, username):
      self.username = username

    def say_id(self):
      print("My id is {}".format(self.id))
    def say_username(self):
      print("My username is {}".format(self.username))

I believe it is the purpose of the abstraction, which enforces that the sub-classes must have their own self-defined say_id methods.

1 Like