Skip to main content
Home  ›  Blog

Content-Type Composition and Inheritance

2sxc 18.02 introduces Content Type Composition, which lets you inherit field definitions across content types. Check it out!

What Problem Does Content-Type Composition Solve?

There are many scenarios where a lot of the content-types have very similar fields. Here's a simple example:

  1. You have a Person Content-Type with fields like NameEmailPhoneSalutation
  2. You have a Company Content-Type with fields like NameAddressPhone
  3. You want to create a Contact Content-Type with fields like NameEmailPhoneAddressSalutationRelationship

There are many more sophisticated examples, but what they all have in common is that certain aspects of the field, such as it's description, formulas and more should be the same, and they should stay the same even if changes are applied.

Previously the developer had to keep track of these changes manually, and apply them to each copy of the field definition in other content types. 

How to Use Content-Type Composition

With Content-Type Composition, you can create a new Contact Content-Type by combining fields from Person and Company. This is what you could do:

Field Person Company Contact Notes
Name 🔊 Master 🚫 Own Field 🔗 Inherit Company name has different description etc. so it does not inherit
Email 🔊 Master   🔗 Inherit  
Phone 🔊 Master 🔗 Inherit 🔗 Inherit  
Address   🔊 Master 🔗 Inherit  
Salutation 🔊 Master   🔗 Inherit  
Relationship     🚫 Own Field

This is just a simple example - in most cases you'll probably even go a different way, and create a master-type which just holds the shared fields:

Field PersonShared Person Company Contact Notes
Name 🔊 Master 🔗 Inherit 🚫 Own Field 🔗 Inherit Company name is different so it does not inherit
Email 🔊 Master 🔗 Inherit   🔗 Inherit  
Phone 🔊 Master 🔗 Inherit 🔗 Inherit 🔗 Inherit  
Address 🔊 Master   🔗 Inherit 🔗 Inherit  
Salutation 🔊 Master 🔗 Inherit   🔗 Inherit  
Relationship       🚫 Own Field

Why not Content-Type Inheritance?

OOP software developers will intuitively assume that Content-Type Inheritance is the logical choice. But composition is much more flexible.

  1. You can inherit only a sub-set of fields from any master.
  2. You can inherit fields from multiple masters.
  3. You can inherit fields from masters and then add more fields.
  4. You can inherit some fields, but specifically implement certain fields yourself, for example when the Name on Company above should have a different description.

Based on our experience, research and enterprise implementations of other systems, we decided that composition is clearly the better choice.

Find out More

This feature is robust and has been used internally in 2sxc for about a year now.

Read more about this in the docs and try it out. You'll need 2sxc 18.02.

We would like to note that this is a very advanced feature which will save you countless hours, so we decided to make it a patrons feature for our supporters. If you are not yet a sponsor of 2sxc, you can still use this feature, but it will show license warnings. 

With ❤️ from Switzerland,
iJungleboy


Daniel Mettler grew up in the jungles of Indonesia and is founder and CEO of 2sic internet solutions in Switzerland and Liechtenstein, an 20-head web specialist with over 800 DNN projects since 1999. He is also chief architect of 2sxc (see github), an open source module for creating attractive content and DNN Apps.

Read more posts by Daniel Mettler