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

**URL:** <https://forum.canton.network/t/how-can-we-implement-or-simulate-inheritance-in-daml/6082>\
**Category:** App Development\
**Tags:** daml\
**Created:** [February 7, 2023, 3:06pm UTC](https://forum.canton.network/t/how-can-we-implement-or-simulate-inheritance-in-daml/6082 "2023-02-07T15:06:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lashenhurst](https://avatars.discourse-cdn.com/v4/letter/l/71e660/32.png) [@lashenhurst](https://forum.canton.network/u/lashenhurst)\
**Post date:** [February 7, 2023, 3:06pm UTC](https://forum.canton.network/t/how-can-we-implement-or-simulate-inheritance-in-daml/6082/1 "2023-02-07T15:06:09Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![a\_putkov](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/a_putkov/32/2971_2.png) [@a\_putkov](https://forum.canton.network/u/a_putkov)\
**Post date:** [February 7, 2023, 3:19pm UTC](https://forum.canton.network/t/how-can-we-implement-or-simulate-inheritance-in-daml/6082/2 "2023-02-07T15:19:04Z")

</div>

Take a look at [Daml Interfaces](https://docs.daml.com/daml/reference/interfaces.html), which are used extensively in [Daml Finance](https://docs.daml.com/daml-finance/index.html).

---

<div class="post-metadata">

**Author:** ![lashenhurst](https://avatars.discourse-cdn.com/v4/letter/l/71e660/32.png) [@lashenhurst](https://forum.canton.network/u/lashenhurst)\
**Post date:** [February 7, 2023, 3:20pm UTC](https://forum.canton.network/t/how-can-we-implement-or-simulate-inheritance-in-daml/6082/3 "2023-02-07T15:20:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![a\_putkov](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/a_putkov/32/2971_2.png) [@a\_putkov](https://forum.canton.network/u/a_putkov)\
**Post date:** [February 7, 2023, 4:47pm UTC](https://forum.canton.network/t/how-can-we-implement-or-simulate-inheritance-in-daml/6082/4 "2023-02-07T16:47:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lashenhurst](https://avatars.discourse-cdn.com/v4/letter/l/71e660/32.png) [@lashenhurst](https://forum.canton.network/u/lashenhurst)\
**Post date:** [February 7, 2023, 5:11pm UTC](https://forum.canton.network/t/how-can-we-implement-or-simulate-inheritance-in-daml/6082/5 "2023-02-07T17:11:18Z")

</div>

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!
