Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

design patterns python - restrict what methods of the wrapped class to expose

class User:
    _persist_methods = ['get', 'save', 'delete']

    def __init__(self, persister):
        self._persister = persister

    def __getattr__(self, attribute):
        if attribute in self._persist_methods:
            return getattr(self._persister, attribute)
Source by www.toptal.com #
 
PREVIOUS NEXT
Tagged: #design #patterns #python #restrict #methods #wrapped #class #expose
ADD COMMENT
Topic
Name
5+1 =