Created
June 10, 2020 19:42
-
-
Save dylanjf/c149b7a7d92f8b61da8851d508a7ab9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, **data): | |
num_1 = data.get('num_1') | |
num_2 = data.get('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, **data): | |
num_1 = data.get('num_1') | |
num_2 = data.get('num_2') | |
num_3 = data.get('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)) | |
print(ch1.thing(requests_v2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment