Hi All,
using interfaces for behavioural testing seems a common pattern in go:
if typed, hasCapability := d.(Capability); hasCapability...
I have the requirement to dynamically compose interfaces at runtime, i.e. I cannot know upfront which set of interfaces a resulting type will support:
type resultingType interface {
basicCapability
...any combination of additional capabilities
}
If there is only a single additional/optional capability to implement that is simple to solve, e.g. by implementing a wrapping struct that embeds the basic capability and adds an additional capability. Applying this pattern across multiple layers (stack of wrapping structs does not work as the embedded interfaces don't bubble up).
However, the number of additional capabilities that a type might have to support could be bigger (think of physical meters which could supply power, energy, currents, frequency etc).
I'm wondering if using a pattern of dynamic composition is sound, if the the go:generate approach is a good one or if there are better ways?
Kind regards,
Andi