obj pickle load(open('shopfile pkl''rb')obj serverobj chef (obj order('lsp'lsp orders from bob makes pizza oven bakes lsp pays for item to this just runs simulation as isbut we might extend the shop to keep track of inventoryrevenueand so on--saving it to its file after changes would retain its updated state see the standard library manual and related coverage in and for more on pickles and shelves oop and delegation"wrapperproxy objects beside inheritance and compositionobject-oriented programmers often speak of delegationwhich usually implies controller objects that embed other objects to which they pass off operation requests the controllers can take care of administrative activitiessuch as logging or validating accessesadding extra steps to interface componentsor monitoring active instances in sensedelegation is special form of compositionwith single embedded object managed by wrapper (sometimes called proxyclass that retains most or all of the embedded object' interface the notion of proxies sometimes applies to other mechanisms toosuch as function callsin delegationwe're concerned with proxies for all of an object' behaviorincluding method calls and other operations this concept was introduced by example in and in python is often implemented with the __getattr__ method hook we studied in because this operator overloading method intercepts accesses to nonexistent attributesa wrapper class can use __getattr__ to route arbitrary accesses to wrapped object because this method allows attribute requests to be routed genericallythe wrapper class retains the interface of the wrapped object and may add additional operations of its own by way of reviewconsider the file trace py (which runs the same in and )class wrapperdef __init__(selfobject)self wrapped object def __getattr__(selfattrname)print('traceattrnamereturn getattr(self wrappedattrnamesave object trace fetch delegate fetch recall from that __getattr__ gets the attribute name as string this code makes use of the getattr built-in function to fetch an attribute from the wrapped object by name string--getattr( ,nis like nexcept that is an expression that evaluates to string at runtimenot variable in factgetattr( ,nis similar to __dict__[ ] designing with classes