0

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.

4
  • 5
    This arrangement is not going to work. You've created a conflict in your requirements that cannot be reconciled (both plugins need to be first in line). This isn't a technological problem; it is a requirements problem. Fix the requirements so that the conflict is no longer necessary, or change the requirements so that a reasonable arrangement can be made between the two plugins. Commented Aug 9, 2016 at 21:11
  • Please explain what kind of consequences will happen if e.g. Plugin A wins and Plugin B doesn't. If this is related to display e.g. tiled windows, content on a web page, search results etc., the consequence should be minor as long as a hidden ordering is imposed (such as the relevance based rating you proposed) to break the ties.
    – rwong
    Commented Aug 10, 2016 at 5:22
  • 1
    Have you considered that there should not be a reason for a plugin to have to require it's value to be at a specific point in an array? Nor do you want plugins to decide on their own how important they are. The influence of plugins on your application should be as much isolated as you can get them to prevent plugins causing bugs or crashes in the application. Commented Aug 10, 2016 at 9:30
  • @JonathanvandeVeen I think that is actually a really good point. A plugin knows that it is not alone so it should not treat data like it is the only one using it. That's the real solution I guess, fixing the requirement of being first as Robert also stated
    – Aurus
    Commented Aug 10, 2016 at 14:02

2 Answers 2

2

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)

1

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".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.