I'm going through the plug-in tutorial and reading...
# plugins
l
I'm going through the plug-in tutorial and reading the docs and I'm curious: is it possible to use a target as a template and then reference that template in another target of the same type, but override only some subset of fields? So I could use either target and a change in the first would affect the second, unless the change is in the overridden field.
Or is this functionality what a macro does?
f
Yes. Targets at their core are just collections of fields. So let's say you have target X with fields A, B, and C. You can then define target Y and give it fields A, B, and C1 where C1 is a subclass of C. Y will have effectively overridden field C.
even better a
FieldSet
looking for fields A, B, and C will match both X and Y targets. But a
FieldSet
looking for fields A, B, and C1 will only match Y.
This provides a way to differentiate between X and Y when need to, but by looking at their fields and not the name of the target type.
You can see this pattern in some of the dependency inference rules for example where the
Dependencies
field will be subclassed and associated with a subset of (or one) target type to narrow the applicability of the dependency inference rule.
search
compute_value
for other examples in the code base
(where subclasses will override that method to provide different behavior than the base class field type)
l
Thanks for that explanation!