Skip to content

31. An Abstract Connector Class

Difficulty: Medium · Topic: OOP & classes

Pipelines talk to many storage systems through one interface. Write:

Your code runs in CPython on our servers against 6 tests, including hidden ones.

Sample test

s3 = S3Connector('raw')
db = DbConnector('orders')
s3.write('o1.json', {'id': 1, 'amount': 30})
written = s3.copy('o1.json', db, new_key='o1')
(written, db.rows, s3.objects)

Expected: ('o1', {'o1': {'id': 1, 'amount': 30}}, {'raw/o1.json': {'id': 1, 'amount': 30}})

Hints

Hint 1Inherit from abc.ABC and mark methods with @abstractmethod; Python then refuses to instantiate the class until every abstract method is implemented.
Hint 2Concrete methods in the base class can call the abstract ones: each subclass supplies its own version.
Hint 3isinstance(value, dict) checks the row type.

Learn the concepts

More Python problems

All Python problems