dock
dock copied to clipboard
Kernel for init all subsystems
It would be more clear to have a kernel to init all subsystem then isn't necessary to call in each subsystem package a hidden register function
Prototype
Caller:
package main
func main() {
kernel := kernel.Init()
}
Init Kernel:
package kernel
func Init() {
k := new(kernel)
k.RegisterSubsystem(new(subsystem.Memory))
// soon on ...
}
Kernel:
package kernel
type Kernel struct {
subsystems map[string]subsystem
}
func (k *kernel) RegisterSubsystem(s subsystem) {
k.subsystems[s.Name()] = s
}
What do you think?
If it's this idea good then I can implement this idea
The kernel package is more clear, but i believe its still nessary to call register func in each subsystem, therefore no need to modity the kernel package every single time you add a new subsystem.
Your approach is to create a new subsystem package and internally it registers this new subsystem by name afterwards it injects a new instance of this subsystems. If you would remove the registration process from the subsystem then it's cleaner and it reduces the complexity because you need to make sure at n * places you called the register function.
Subsystem register process
Pro
- Self-contained
- No need for a new abstraction
Contra
- Increase complexity for a developer (tree path is missing)
- N places * register call
Kernel register process
Pro
- Verbose and clear what is registered
- Reduce complexity for developer
- Dependencies are clear
Contra
- New abstraction
- 2 * packages necessary for registering a new subsystem
What do you think?