Skip to content

Object Oriented Programming

Kango edited this page May 19, 2018 · 2 revisions

Object oriented programming (OOP)

The thing about classes or OOP is that with a class you can have an item like a car in your code in one place. Very tidy.

Otherwise (without the OOP architecture) you would have variables for the car and functions responsible for these car variables just somewhere in your code:


color CarC;
float Carxpos;
float Carypos;
float Carxspeed;

With OOP you can have the properties and the functions responsible for these in a neat package called class Car. Very good. See above.


    class Car {
        color CarC;
        float Carxpos;
        float Carypos;
        float Carxspeed;
    }
    

A class represents the blueprint for creating car(s). A single car is called an object.

When invoking a 2nd car you use the same class but with different values for the properties. So the car is the cookie but the class is the cookie maker. When we invoke a car from the class we say we instantiate one object (real item) from the class (the abstract idea of the item).

Every class has a constructor inside the class, it has exactly the same name as the class and does not have a return data type, not even void. The constructor instantiates a new object and can give values to it.

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