Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel for init all subsystems #1

Open
donutloop opened this issue Nov 27, 2018 · 3 comments
Open

Kernel for init all subsystems #1

donutloop opened this issue Nov 27, 2018 · 3 comments

Comments

@donutloop
Copy link

donutloop commented Nov 27, 2018

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?

@donutloop
Copy link
Author

If it's this idea good then I can implement this idea

@philchia
Copy link
Owner

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.

@donutloop
Copy link
Author

donutloop commented Nov 28, 2018

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants