what are design patternsthe examples in design patterns are brief and are written in either +orin some casessmalltalk if you are working in another languageit is helpful to have the pattern examples in your language of choice this part of the book attempts to fill that need for python programmers notes on object-oriented approaches the fundamental reason for using design patterns is to keep classes separated and prevent them from having to know too much about one another equally importantusing these patterns helps you avoid reinventing the wheel and enables you to describe your programming approach succinctly in terms other programmers can easily understand there are number of strategies that oo programmers use to achieve this separationamong them encapsulation and inheritance nearly all languages that have oo capabilities support inheritance class that inherits from parent class has access to all the methods of that parent class it also has access to all its variables howeverby starting your inheritance hierarchy with completeworking classyou might be unduly restricting yourself as well as carrying along specific method implementation baggage insteaddesign patterns suggests that you always program to an interface and not to an implementation putting this more succinctlyyou should define the top of any class hierarchy with an abstract class or an interfacewhich implements no methods but simply defines the methods that class will support then in all your derived classesyou have more freedom to implement these methods as best suits your purposes python does not directly support interfacesbut it does let you write abstract classeswhere the methods have no implementation remember the comd interface to the dbutton classclass dbutton(button)def __init__(selfmaster**kwargs)super(__init__(master**kwargssuper(config(command=self comdabstract method to be called by children def comd(self)pass this is good example of an abstract class here you fill in the code for the command method in the derived button classes as you will seeit is also an example of the command design pattern the other major concept you should recognize is object composition we have already seen this approach in the statelist examples object composition is simply the construction of objects that contain others--the encapsulation of several objects inside another one many beginning oo programmers tend to use inheritance to solve every problembut as you begin to write more elaborate programsthe merits of object composition become apparent your new object can have the interface that works best for what you want to accomplish without having all the methods of the parent classes thusthe second major precept suggested by design patterns is favor object composition over inheritance