CSCA48H3 Lecture Notes - Lecture 6: Init

83 views3 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents