I understand that Solidity supports contract polymorphism, but what pattern would one use to create abstract data types for use in derived contracts?

Motivating example: Say I have an abstract Storage contract. I want to implement a derived contract OrderStorage that implements a struct Order and a method append(Order[] memory _orders), and another derived contract CustomerStorage that implements struct Customer and append(Customer[] memory _customers).

Is there a way that I can define the append method once in the Storage base contract and then just plug in the right struct in the derived contracts, without redefining the append method in each derived contract?

If what I'm seeking is impossible, are there any viable alternative patterns that would be better than redefining append from scratch on every derived contract?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.