OOP (Object-oriented programming)

Discussion in 'Spigot Plugin Development' started by yhl, May 1, 2017.

  1. yhl

    yhl

    I was wondering if someone could explain to me what OOP is? I've never heard of it (Okay, maybe like once or twice but never figured out what it meant), and I want to finally figure it out :p

    Also, I know I can search this up, but I was wondering if you could give me a simple answer.

    Thanks!
     
  2. Basically put you can create instances of classes as "objects" that can store data and be manipulated instead of simply using a logical procedure to process some data.

    An example would be like in a 1v1 plugin where you have matches. I've done this before. I created a class "Match" as an object and then a "MatchManager" to interface with the match objects to get and store data for each match. This makes it really simple to keep track of the running matches and players.
     
    • Like Like x 4
    • Agree Agree x 1
  3. Yep almost everything in a java is an object. Classes, variables etc. some can be more complicated than others. The concept is that you create an object it stays in memory and you can use pointers to later access said object and modify it.

    For example a Player in spigot is an object.

    This object has multiple fields and methods contained within.

    You can access and modify some of these. Like Player.getHealth() and setHealth(). Others we can't or can't easily modify like the players Uuid.

    Through these objects working together we create plugins that use these objects and interact with them to modify the core game.

    Minecraft itself is full of objects the API just gives us an easy way to interact with it.


    Sent from my iPhone using Tapatalk
     
    • Useful Useful x 1
  4. There is nothing particularly simple about OOP, the badly informed replies here will just mislead the OP and leave them without any real idea what they are doing.

    I will sum it up a bit more concisely:

    OOP is a style of programming that focuses on objects (a unit of data, and behavior related to that data) instead of standalone algorithms and functions that manipulate whatever data you pass to them.
    It is meant to be more modular (each object contains everything it needs to do a specific task or be a specific thing), allowing code to be easily reusable and expandable.
    It also must support polymorphism, which is the process of an object class extending/inheriting another class, copying all of its behavior and potentially changing or adding features. The inheriting version can be used as a stand-in or replacement for the parent class anywhere that the parent could be used. Examples would be the java List class, which defines basic behavior (getting and setting elements, clearing the list, ect) and is extended by ArrayList, LinkedList and several other types of lists.

    In older styles such as procedural programming, there is no way to directly connect a method or algorithm to a type of data, or individual data structure. It is much simpler, but tends to get extremely complicated and confusing in large projects, and harder to update over time.
     
    • Winner Winner x 2
    • Agree Agree x 1
    • Useful Useful x 1
  5. OOP is the best way to handle your plugins safely, easily and without problems :) Also its almost necessary to use it while coding bog plugins such as minigames. Recommend you to learn !
     
    #6 Drawethree, May 1, 2017
    Last edited: May 1, 2017
    • Optimistic Optimistic x 3
  6. that is not OOP at all.
    FOP would also work just as good in this case, so no, that's not OOP.

    OOP is when everything focuses around objects. A Java variable can be at base level an instance of java.lang.Object, which is a class / object. you cannot make a base-line function without an owner in java, compared to e.g. kotlin and clojure.
    FOP, function-oriented programming, exists in e.g. Kotlin, which combines the two worlds, while it is the only way of doing Clojure, at least in a sense, since you can still generate classes reflectively.
    e.g. this is FOP in Clojure, which can actually be used as a main class:
    Code (Clojure):
    (ns spigot.test
      (:gen-class)) ; Generates a class and defaults :main to true, thus requiring a main method.

    (defn -main ; the main method made. requires the - because the :prefix in :gen-class is defaulted to it.
      [& args] ; collect extra arguments provided into a vector called args.
      (prn "This method was run!") ; prints "This method was run!" and the exits, as it's the last method run.
      )
    and it's not only for big plugins, but also for small plugin, programs, anything. OOP is how you code Java, simply put. If you write a method, you've made something within an object, thus OOP.
    if you write something like i did in clojure it's both worlds FOP and OOP at the same time due to the :gen-class, but it's mostly FOP of course.
     
  7. I..
    What?
    ಠ_ಠ
     
  8. That is some of the most distressingly obtuse code i have ever seen. It seems to be a special habit of the JVM language family to take something that works fine and turn it into an unrecognizable mess that requires relearning everything you know about syntax and memorizing tons of unique and bizarre keywords - without actually adding any functionality, because JVM. At least Kotlin actually looks something like other programming languages under all the sourcecode-sugar (crack).
     
    • Funny Funny x 1
  9. BananaPuncher714

    Supporter

    tl;dr
    You have an object that is a type of another object, but with more specific variables and methods. So it's like saying salt is a mineral and a mineral is a rock, but salt is a lot more precise than a mineral because salt has other properties besides also having what properties a mineral has. Everything is a more specific subclass/child of a superclass/parent, so everything indirectly inherits the properties of Object( The most basic of all basic classes in Java ). Each class can only extend/inherit one class, but they can implement many interfaces( they're like objects too ), which only tell the class what methods it must contain. You can create many copies of the same class, which are called instances/objects. Each one can have different properties because they are independent copies of the original( polymorphism ). That's pretty much how the entire Spigot server works. Each player is a copy of the Player class, but each one has their own properties( name, location, inventory, etc. ) and can still do the same things( kill people, eat food, die ).

    even shorter tl;dr
    All things( classes ) are a copy( subclass ) of an even more generic copy( superclass ), and you can create copies( instances ) of those copies( classes ) that are copies( subclass ) of a copy( superclass ). :D
     
    • Like Like x 1
  10. it does add things, but it's all functions and macros (which they are excused of cause of the FOP, so they really cant do much)
    clojure is also reflection based btw.
     
    • Winner Winner x 1
  11. I've learned it from tutorial point. OOP is not something that you can sum in one sentence but start learning it (very recomended) will give you some direction.
     
    • Agree Agree x 1
  12. I was going to ask what sort of awful, inefficient and massive bytecode whale it compiles down to, but..

    Decompile clojure class file, expose brain, never unsee horror.
     
    • Funny Funny x 3
  13. Just as @Voigon said, the best way to learn about OOP is to actually use it. Please, give us an example of something you've coded or something you would like to create and there's probably an OOP way of doing it.
     
    • Agree Agree x 1
  14. if you use it a lot you'll get used to the whale ;)
     
  15. Never actually used Clojure (or any Lisp) in any non-trivial project, but that right there looks neat. Very concise and clear. Been meaning to get more into Clojure for a while. I just don't think I'd feel comfortable in a dynamically typed language :p.
     
    • Like Like x 1
  16. neither did i.
    [​IMG]
    it's now 37.87% of what i've programmed in the last 7 days (42hours, 21 mins) which is 16.037945 hours.