Abc's and class inheritance
Level: Advanced (score: 4)
ABC
's or Abstract Base Classes
are great to enforce a common API for your subclasses.
You define one or more methods and/or properties as abstract in the base class, and if the subclass does not implement them it raises a TypeError
. In this bite you will use this concept as follows:
- Define a Challenge base class that inherits from
ABC
(given), its constructor receives anumber
and atitle
attribute. - On Challenge define an
abstractmethod
calledverify
and aproperty
(< 3.3 it would be anabstractproperty
) calledpretty_title
. - Create the
BlogChallenge
andBiteChallenge
classes which both inherit fromChallenge
. Note that they would raise aTypeError
at this point, exactly what you want: enforcing the use of the abstract method/ property. BlogChallenge
andBiteChallenge
's constructors call the parent constructor (don't worry it's supercool, remember: we use Python3 so adjust your syntax), and both receive an extra argument in the constructor:merged_prs
forBlogChallenge
andresult
forBiteChallenge
.- Implement the required methods and properties, refer to the tests what they need to return.
Get coding, learn more about classes, and have fun!