improved proxy implementation.

proxy must now contain all public methods that the subject has.
This commit is contained in:
tylerlaberge
2016-08-24 21:04:35 -04:00
parent 519592eaa5
commit 5cef83cf60
2 changed files with 46 additions and 7 deletions
+20 -1
View File
@@ -1,4 +1,7 @@
class Proxy(object):
from abc import ABCMeta
class Proxy(object, metaclass=ABCMeta):
"""
Base Proxy class as part of the Proxy design pattern.
"""
@@ -9,6 +12,22 @@ class Proxy(object):
@param subject: The real subject this proxy calls upon.
"""
self._subject = subject
self._validate()
def _validate(self):
"""
Validate that the subject and this proxy follow the same interface.
@raise AttributeError: If the subject and this proxy do not follow the same interface.
"""
for attr in dir(self._subject):
if attr.startswith('_') or attr.startswith('__'):
continue
elif not callable(getattr(self._subject, attr, None)) or not callable(getattr(self, attr, None)):
raise AttributeError('Subject and Proxy must follow same interface')