:\codepython import converters prog converters uppercase(open('trispam txt')open('trispamup txt'' ')prog process( :\codetype trispamup txt spam spam spambutas suggested earlierwe could also pass in arbitrary objects coded as classes that define the required input and output method interfaces here' simple example that passes in writer class that wraps up the text inside html tagsc:\codepython from converters import uppercase class htmlizedef write(selfline)print('%sline rstrip()uppercase(open('trispam txt')htmlize()process(spam spam spamif you trace through this example' control flowyou'll see that we get both uppercase conversion (by inheritanceand html formatting (by composition)even though the core processing logic in the original processor superclass knows nothing about either step the processing code only cares that writers have write method and that method named convert is definedit doesn' care what those methods do when they are called such polymorphism and encapsulation of logic is behind much of the power of classes in python as isthe processor superclass only provides file-scanning loop in more realistic workwe might extend it to support additional programming tools for its subclassesandin the processturn it into full-blown application framework coding such tool once in superclass enables you to reuse it in all of your programs even in this simple examplebecause so much is packaged and inherited with classesall we had to code was the html formatting stepthe rest was free for another example of composition at worksee exercise at the end of and its solution in appendix dit' similar to the pizza shop example we've focused on inheritance in this book because that is the main tool that the python language itself provides for oop butin practicecomposition may be used as much as inheritance as way to structure classesespecially in larger systems as we've seeninheritance and composition are often complementary (and sometimes alternativetechniques designing with classes