CSCA48H3 Lecture Notes - Lecture 6: Init
Document Summary
Csca48 - lecture 06 - abc + container adt. We looked at this last week, albeit a bit briefly. Sometimes it"s useful to specify one or more methods in a class that every subclass must implement. Since the details of these methods can vary depending on the subclass, a good way to code this in python is with the use of an abstract base class. A python class is abstract if it has one or more abstract methods . Here"s how to define an abstract base class. Define your abstract class as a subclass of abc. Decorate each abstract method by adding @abstractmethod on the line immediately before the line where you define you method. You may just use pass as the body of your abstract method. Python will not let you instantiate an abstract class. It will let you instantiate subclasses that include definitions of the abstract methods.