Project Structure

Discussion in 'Plugin Development' started by FlareLine, May 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    FlareLine

    Hi Everyone,
    All this forum is about, is code structure.
    How do you plan your plugin? What sections do you separate classes into?
    I continually find myself creating empty packages, or classes that can't reference other classes they are dependent on...
    Any discussion of this topic is welcome!
     
  2. Offline

    DJSkepter

    When I start a plugin, I normally do these few things (if it's a fairly large plugin):
    [1] List all of the features/commands/permissions which the plugin will have and do
    [2] List all of the classes which will carry out what action
    [3] Write pseudo (fake) code for all of the complicated methods.
     
    TGRHavoc likes this.
  3. Offline

    TGRHavoc

    FlareLine
    I tend to have the "Main" class inside its' own package then everything else I put into its own folder inside the mains' package. For example, all the event handler would go in a "handlers" folder and all extraneous methods go into a "methods" folder and, well I think you get the point :)
     
    DJSkepter likes this.
  4. Offline

    FlareLine

    I see. How do you organize your references?
    Do you create a constructor in every class and reference back to instances of others, or do you simply instantiate them again?
     
  5. Offline

    lukewizzy

    In terms of planning, I write a lot of the methods I'll need regularly into an API before I create event listeners, commands, etc. I take quite a lot of time over this because I don't want to have to go back and re-write most of it later on because I hadn't accounted for certain things. I've made that mistake before..

    Usually my main package only contains the main class. I then put classes that do similar things into groups, like this:
    http://gyazo.com/01b5fd36f1b4cc708a81fb59b16474e5

    I create a new class for every command, event listener custom inventory, timer, etc
    Sometimes I even have sub-packages in my API if I've got a load of related classes, like this:
    http://gyazo.com/52e3c24da0302b8355174fd8e074c97f
     
  6. Offline

    TGRHavoc

    FlareLine
    It depends really.. If it's a class that has other useful methods inside, I will generally instance it but, if it's just a one time method call, i'll just create a new instance there and then..
     
  7. Offline

    FlareLine

    lukewizzy This is very helpful to me. I never previously thought to throw all my utilities into an API package. Cheers!
     
    lukewizzy likes this.
  8. Offline

    lukewizzy

    You're welcome :)

    Also it's not a major thing but I forgot to mention it, I generally have a config data file with variables from the config in a class (set in the onEnable) so I don't have to keep referencing the config directly
    And sometimes I'll make a class that just holds itemstacks so they're all in the same place if I want to change them, so if I use the same item in multiple places or can't find it quickly then I can easily edit it
     
Thread Status:
Not open for further replies.

Share This Page