factory method in python


class ObjectStore:
""" a generic class to store objects either to SQL or the filesystem
the interface storeaway uses a specific storeformat and gets the associated implementation storer"""
def storeaway(self, storable, storeformat):
storer = factory.get_storeaway(storeformat) """get implementation for storeaway using the storeformat"""
storeable.storeaway(storer) """invoke the implementation of storeaway for the given format"""
return

class storeawayFactory:
def __init__(self):
self._creators = {}
def register_format(self, storeformat, creator):
self._creators[storeformat] = creator
def get_storeaway(self, storeformat):
creator = self._creators.get(storeformat)
if not creator:
raise ValueError(storeformat)
return creator()

factory = storeawayFactory()
factory.register_format("SQL", SQLStoreaway)
factory.register_format("FILE", FileStoreaway)

In the final object to work with we need to implement the