Role Pattern usage based on examples: User Template with choices vs choices on the sub-templates?

Hi @StephenOTT !

I’ll try to answer each of your raised questions:

  1. The approach shown here tries to separate code from data. The main benefit of this approach over coupling the choices with the data is that upgrades of your Daml code will be much easier. I’ll get into that at the end.
  2. This approach works as well, however, upgrading your Daml code will become a lot more involved.
  3. Same as 2).
  4. The main reason is upgrading, but I could also imagine that the UI code gets a bit easier this way.
  5. I wouldn’t be aware of a better transaction structure this way.
  6. No, I don’t think so. You could just as well return them in the choices.

Imagine that you decided to have all your choices along with their respective data templates. Now if you wanted to add a new choice, you would have to archive all those active data templates, then recreated and potentially update them to offer this new choice.
If you went with the approach shown here, all your choices are in the User contract. To add a new choice, you only have to find the User role contract, archive it and recreate it with the new User template with the added choice. This is easier, because there are potentially a lot of SellOffer contracts around, while there is only one User contract for each user. Also, the data contained in the old and new User contract is most likely the same, so the transition will be a trivial archive followed by a create. After this, the user will have the new choice available.

2 Likes