Günter Zöchbauer
Günter Zöchbauer

Reputation: 657248

How to treat resources that extend other resources

When I generate code from StructureDefinitions, it would be obvious to use the class for the resource referenced in base as superclass.

A resource that is based on another resource can change the the type of a property of the base resource (for example from String to List<String> if max="0" is overridden by max="*").

This would break in strongly typed languages because a subclass has to conform to the interface of the super class (can only specialize but not generalize).

What would be the correct strategy to deal with that?

I can use snapshot instead of differential and not extend the class of the base resource.

Should I still extend one of the more general super classes like Element, BackboneElement, Resource, DomainResource?

Are there any flaws in my reasoning?

Upvotes: 0

Views: 148

Answers (1)

Lloyd McKenzie
Lloyd McKenzie

Reputation: 6793

Resources can't "extend" other resources. If the base resource has a cardinality for an element of 1..1, the derived model can't change the lower cardinality below 1, nor the upper cardinality above 1.

The primary way of "extending" a resource is to make use of the "extension" element which is defined as being 0..* pretty much everywhere in the base resources. So technically when you're creating a profile, you're always constraining - either tightening down core elements or constraining expectations for at least some of the repetitions of the "extension" element.

You can find more information about allowed cardinality changes here

Upvotes: 1

Related Questions