Resource Modularity - API for Modular Programming

Discussion in 'Spigot Plugin Development' started by Desetude, Feb 18, 2017.

  1. What is Modularity?
    Modularity is an API which allows the easy use of modular programming.

    Project (Open source, MIT):
    Getting Started:
    Simple example:

    What is a Modular Programming and why would I want to use it?
    Modular programming is a way of designing a program that splits it up into different sections, 'modules', each one handling one aspect of the program. I think you should be designing your programs in a modular way for three reasons:
    • Maintainability - If you split up your program into different, isolated modules, the different functions of the programs will not be grouped together and it is much easier to be able to identify the sections of code relating to the function you are looking for.
    • Substitutability - Modules can be easily substited for something else withtout other modules in the program being affected as there is less dependence between the features that are not directly related.
    • Encapsulation - In a non-modular program, the different features may depend on other features' implementation details, whereas in Modular programming, the different modules hide their implementation details from eachother in order to have a high substitutability.
    How does Modularity help with modular programming?
    Modularity helps with the registering and injection of modules. For example, to mark a class as a Module, all that needs to be done is for it to be annotated with '@Module' and a name to be given to it, after that a 'ModuleLoader' must be instantied, which loads all the Modules, without any modules having to be specifed as the program's classes are scanned at compile-time for the '@Module' annotation. The modules are then loaded and injected by Guice.

    Is this relevant at all with Bukkit?
    I would say that Modular programming is especially important when making Bukkit plugins for servers as most servers have a huge amount of different features that can be hard to maintain without programming in a modular way.
    Also, I have created a Guice module for Bukkit, which adds a few Bukkit-specific features to Modularity.

    What do I need to know to be able to use this?
    To be able to use Modularity, you will need to be quite comfortable with Guice injection, although if you're not, it wont be hard to learn as the documentation is amazing for it at

    Alos, Modularity uses Java 8, Java 7 is not supported.

    The idea for this came from the SKCraft Plume project which is what I based some of the code from, making it much more flexible, documentating it and making it independant of all the other SKCraft features.

    Any feedback on the API or the post itself would be greatly appreciated.
    • Like Like x 1
  2. I just can't find reason why would you want to use this...
  3. The main use of this is something like a server core where there are a large amount of different features that have to be implemented. If you do it in a modular way, it's much easier to organise and maintain. It's not for small plugins.
  4. What about just splitting big plugin into small plugins, or what about just creating separated packages?
  5. 1. Splitting it up into smaller plugins can be harder to maintain as you have to deal with the dependencies between them, also, it if there are a large amount of plugins it would be quite a big pain if it's part of the server core and multiple maven dependencies have to be used.
    2. Seperating packages is just a different solution to the same problem. But then, you still need to manage all the different features in the packages, in a large server core, you could easily be registering 50+ listeners and commands in the plugin class, which could get very chaotic, once again, harder to maintain.
  6. Inkzzz

    Resource Staff

    Modular code is extremely proficient and predominant.
  7. You have such a nice tool called "packages", there is really no need to use anything else for such job. Huge systems aren't a problem, since we are using OOP. Why would you need 50+ listeners i have no idea, maybe youre programming style is just "chaotic".
    Im making systems for more then 8 years in all kinds of languages and i just can't see how this could be helpful, unless you have terrible programming style. Even in this case, this shouldn't be a solution.
    • Agree Agree x 1
    • Optimistic Optimistic x 1
  8. Modules are a great thing. If used in the proper environment.
    The idea of modules is to split sections into smaller bits so you can easily replace and update specific parts. But this is pretty much what bukkit plugins do. When you have a custom program this could be effective, but in the current scenario I don't see much use for it. Most of the time it would be preferred and even more efficient to use a core plugin with a variation of plugins depending on it for different servers.
    • Like Like x 1