to help with implementing subclassesthe two methods that are not specified raise notimplementederror this is common way to specify abstract interfaces in python when abstract base classes seem too heavyweight the methods could have empty implementations (with pass)or could be fully unspecified raising notimplementederrorhoweverhelps the programmer understand that the class is meant to be subclassed and these methods overriddenempty methods or methods that do not exist are harder to identify as needing to be implemented and to debug if we forget to implement them now we have template class that takes care of the boring detailsbut is flexible enough to allow the execution and formatting of wide variety of queries the best part isif we ever want to change our database engine from sqlite to another database engine (such as py-postgresql)we only have to do it herein this template classand we don' have to touch the two (or two hundredsubclasses we might have written let' have look at the concrete classes nowimport datetime class newvehiclesquery(querytemplate)def construct_query(self)self query "select from sales where new='true'def output_results(self)print(self formatted_resultsclass usergrossquery(querytemplate)def construct_query(self)self query ("select salespersonsum(amtfrom sales group by salesperson"def output_results(self)filename "gross_sales_{ }formatdatetime date today(strftime("% % % "with open(filename' 'as outfileoutfile write(self formatted_resultsthese two classes are actually pretty shortconsidering what they're doingconnecting to databaseexecuting queryformatting the resultsand outputting them the superclass takes care of the repetitive workbut lets us easily specify those steps that vary between tasks furtherwe can also easily change steps that are provided in the base class for exampleif we wanted to output something other than comma-delimited string (for examplean html report to be uploaded to website)we can still override format_results