How can we implement (or simulate) inheritance in DAML?

Hi all,

Looking for a little input on increasing template flexibility through inheritance, or something like inheritance.

Prime example here being a financial product including underlyingAssets : [Asset] with the desire to create subclasses under the Asset class, such as RealEstate, FineArt, Commodities. To allow for many different asset types to be used in the creation of the financial product.

Another example might be a financial product made up of other financial products, and the idea would be to have certain templates be subclasses, such that the product of products can take as an input a list of contractId for any of those subclasses.

Thanks in advance!

Take a look at Daml Interfaces, which are used extensively in Daml Finance.

Yeah, I did look at interfaces, correct me if I’m wrong but it seemed to me that they abstract out the behaviour of templates, which is of course useful, but does not necessarily allow me to do what I illustrated above.

Isn’t abstracting the common behavior of the templates representing various asset classes what you’re looking for? This abstraction is what gives you the ability to utilize any of the asset class templates in a template that defines a financial product. Say you define an interface named AssetInterface, which abstracts data items and capabilities common to all your assets, such as the amount of the asset and the capability to transfer the asset to another owner. Then in your financial product template you can reference any asset type using AssetInterface (underlyingAssets: [AssetInterface]) and say get the amount of the asset regardless of whether the asset is an equity or a commodity.
Does this give you what you’re looking for? Or have I misunderstood what you’re after?

Aah okay, I understand what you mean now, it required a slight shift in my thinking away from interfaces purely being used for template choice implementations, but also as objects themselves in their own right. Thanks Alex!