문제

Imagine a simple module-based architecture, there is the Core system that contains an array of random values. It's possible to create modules/plugins that will interact with this array.

  • Plugin A wants to prepend a value in some global array
  • Plugin B wants to the same but a different value
  • Plugin C will put a value to the end

Plugin A and Plugin B both want their data to be in the beginning of the array by definition. Of course it's not possible, but now it completely depends on the execution order, and if the order changes the program behavior will be different.

How would a plugin tell the core system that it really really needs to have this value in the first element of the array. What would the core do if both plugins specify that it "really really needs to be like that".

Ideally a plugin doesn't care and doesn't know about other plugins, imagine there are 20 plugin. It would be a mess if you would try to consider each other plugin in every plugin.

I thought about adding a relevance based rating. For instance each plugin that interacts with the array need to specify an relevance value (an enum for example) that will specify how important it is that the change needs to be exactly like that, or if it doesn't matter.

도움이 되었습니까?

해결책

You really only have two options here:

  • Add a priority (or relevance as you called it) when the plugins register themselves / their action

or

  • Last/First one wins approach. Whatever plugins registers last/first will be the the one that gets the spot at the top of your structure

You can't really do anything else (besides randomly deciding) if you can't solve this contradiction on the requirements side (which is where the real problem is)

다른 팁

Since you haven't given a reason that anything else besides the plugin cares where the start of the global array is you can just tell each plugin, "sure little buddy, you're at the start. By the way, the start for you is at 0xFFFF0042".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top