Hey!
I'd like to extend the functionality of an existing module but cannot find a great way of doing this.
I am currently adding the main module as a dependency to other modules, e.g.
Original module:
type ModuleA struct {}
func (m *ModuleA) Foo() string { ... }
func (m *ModuleA) Bar() string { ... }
Extended Module:
type ModuleB struct {}
// Redefined Foo
func (m *ModuleB) Foo() string { ... }
// Reusing Bar
func (m *ModuleB) Bar() string {
return dag.ModuleA().Bar()
}
This gives me a lot of agency but means that I have to redefine all the functions of ModuleA inside ModuleB to be able to call them π¦
I have tried defining interfaces inside ModuleA so that Foo could accept a module defining PreFoo and PostFoo but then I cannot inject the implementation from outside ModuleA...
Is there a pattern I'm missing or nicer way to extend modules?
Thanks a lot!