Solved Object orientating code question.

Discussion in 'Spigot Plugin Development' started by kadesa, Apr 29, 2017.

  1. Ok, so I have been really wanting to get better at coding as Object orientated, I just dont know how I should set up my objects. I know what object orientated coding is, so please do not tell me what it is.
    I need help on figuring out what to make my objects have. I am working on a supply drop object in my plugin and I just dont know what all to make the object have. Should I make the object basically just have the random spawning stuff and the inventory stuff, or should I have other things in it?

    Now, I am not asking to be spoon fed, but I will not reject any offers. I manly just want a clear understanding on how to structure my objects. Also, if you dont mind, I would also like a link to a good place to learn more on object orientating coding.

    PM me if you want to have a full conversation about anything related to spigot coding.

    Any help will be greatly appreciated. :)
  2. You apparently do not know what Object-Oriented programming is..

    I would suggest you get a good basic java or OOP textbook online, as a pdf, or via your local library system, if you have one (the ones here have hundreds of free programming textbooks online, but it is california..).

    Typically, any methods directly related to the behavior of the object or data that is part of the object goes in the object class. If it is not directly related to it, it should go elsewhere.
  3. could you explain what you mean, I think I understand but I just need a more clear explanation.

    or PM me. Please.
  4. You want to make sure each class has a clearly defined role in what you are trying to accomplish. If you find a class is trying to manage too many tasks, split the class up. Honestly, I don't think this is a question that can be easily answered. Knowing what a class should and should not have comes from experience. Knowing how to properly structure code isn't something you can just read how to do. I have rewritten many plugins throughout the years, because as I have attempted to add features to them, I realize if a I had wrote the plugin in a slightly different way, I could expand upon the plugin far more easily. It is through this experience throughout the years that teaches you how to structure your plugins and the individual classes themselves.

    Sorry if this is not a really definitive answer, but I believe it is true.
    • Like Like x 1
  5. WAS


    I would do multiple classes for each part of the drop system. You have your DropSpawn class, your DropInventory class, etc. That way nothing is too blogged down, and they all speak towards that they do. For example, the vehicle classes example.

    You would have a basic Vehicle class which you than can extend with your Car, and your Truck classes. You could have a "Load" class which represents the loads based on the instnace. A car wouldn't have as much capacity as a truck, but both are related. Just as both a Car and Truck is a vehicle.
    #5 WAS, Apr 29, 2017
    Last edited: Apr 29, 2017
    • Like Like x 1