OOP

What is OOP?
OOP is object oriented programming. It is a powerful paradigma that is used in most programming languages.

Imagine you have a pong game and have a ball in your program.

It has an x and y position, a color and a size, it can fly and bounce and need to be displayed.

All those variables function used to be separated in a program. Bad.

They all refer to the ball. So in OOP we put it all together in a class Ball.

When you have many balls or asteroids, they all can have different sizes and colors but do all stem from the same class: They share the same properties.

OOP
An object is one entity in your program. It is derived from a Class. The class is the abstract idea of the thing and the object is the real thing. Think of objects as cookies and of the class a cookie maker: there are many objects / cookies but only one cookie maker. To make the object, you use the constructor. The class makes your program better readable since its variables (properties) and methods (word for function within a class) are in one package. Neat.

Example without OOP
Example without OOP (from the processing examples) int rad = 60;       // Width of the shape float xpos, ypos;   // Starting position of shape float xspeed = 2.8; // Speed of the shape float yspeed = 2.2; // Speed of the shape int xdirection = 1; // Left or Right int ydirection = 1; // Top to Bottom void setup {  size(640, 360); noStroke; frameRate(30); ellipseMode(RADIUS); // Set the starting position of the shape xpos = width/2; ypos = height/2; } void draw {  background(102); // Update the position of the shape xpos = xpos + ( xspeed * xdirection ); ypos = ypos + ( yspeed * ydirection ); // Test to see if the shape exceeds the boundaries of the screen // If it does, reverse its direction by multiplying by -1 if (xpos > width-rad || xpos < rad) { xdirection *= -1; }  if (ypos > height-rad || ypos < rad) { ydirection *= -1; }  // Draw the shape ellipse(xpos, ypos, rad, rad); }

Same program as OOP
Same program as OOP Ball ball; void setup {   size(640, 360); background(102); noStroke; frameRate(30); ellipseMode(RADIUS); // Set the starting position of the shape int xpos = width/2; int ypos = height/2; float xspeed = 2.8;  // Speed of the shape float yspeed = 2.2;  // Speed of the shape ball = new Ball (xpos, ypos, xspeed, yspeed); } void draw {   background(102); ball.run; } // ======================================  // classes class Ball { int rad = 60;        // Width of the shape float xpos, ypos;    // Starting position of shape float xspeed;  // Speed of the shape float yspeed;  // Speed of the shape int xdirection = 1;  // Left or Right int ydirection = 1;  // Top to Bottom // constructor Ball(float xpos_, float ypos_,   float xspeed_, float yspeed_) { xpos=xpos_; ypos=ypos_; xspeed=xspeed_; yspeed=yspeed_; }// constructor void run { // Update the position of the shape xpos = xpos + ( xspeed * xdirection ); ypos = ypos + ( yspeed * ydirection ); // Test to see if the shape exceeds the boundaries of the screen // If it does, reverse its direction by multiplying by -1 if (xpos > width-rad || xpos < rad) { xdirection *= -1; }     if (ypos > height-rad || ypos < rad) { ydirection *= -1; }     // Draw the shape ellipse(xpos, ypos, rad, rad); } // method } // class // As you see, class contains variables and methods.

Links
see https://www.processing.org/tutorials/objects/