Skip to content

Instantly share code, notes, and snippets.

@dylanjf
Created June 10, 2020 19:28
Show Gist options
  • Save dylanjf/9e0905d09313dc8303039d369620362c to your computer and use it in GitHub Desktop.
Save dylanjf/9e0905d09313dc8303039d369620362c to your computer and use it in GitHub Desktop.
from abc import ABCMeta, abstractmethod
from typing import Dict
class Base(metaclass=ABCMeta):
def __init__(self, a):
self.a = a
@abstractmethod
def sub_thing(self, **data) -> Dict:
pass
def thing(self, requests):
return [self.sub_thing(**request) for request in requests]
class Child(Base):
def __init__(self, a):
Base.__init__(self, a)
def sub_thing(self, num_1, num_2):
return {'attribute_1': num_1*self.a, 'attribute_2': num_2*self.a}
class Child2(Base):
def __init__(self, a):
Base.__init__(self, a)
def sub_thing(self, num_1, num_2, num_3):
return {'attribute_1': num_1**2*self.a+num_3, 'attribute_2': num_2**2*self.a+3}
if __name__ == "__main__":
requests_v1 = [{"num_1": 3, "num_2": 5}, {"num_1": 4, "num_2": 6}]
requests_v2 = [{"num_1": 3, "num_2": 5, "num_3": 10}, {"num_1": 4, "num_2": 6, "num_3": 20}]
ch1 = Child(a=5)
ch2 = Child2(a=5)
print(ch1.thing(requests_v1))
print(ch2.thing(requests_v2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment