From anonymous, 1 Month ago, written in Python.
Embed
  1. class DocValidator():
  2.         def validate(data):
  3.                 # Validation logic
  4.  
  5. class DocProcessorBase():
  6.  
  7.     validator: DocValidator   # <---
  8.  
  9.         def process_and_save(self):
  10.                 self.validator.validate(data)
  11.                 # Processing logic follows
  12.  
  13. class UserDocProcessor(DocProcessorBase):
  14.         def __init__(self, validator):
  15.                 self.validator = validator
  16.  
  17.         def execute(data):
  18.                 self.process_and_save(data)
  19.  
  20. doc_validator = DocValidator()
  21. data = {} # some data
  22. UserDocProcessor(doc_validator).execute(data)