home/ atoms/ processing-oop-class

Processing classes bundle related fields and methods into reusable, instantiable objects

Object-oriented programming groups data (fields) and behaviour (methods) into classes. A class is a blueprint; an object is one instance of it. The constructor (same name as the class, no return type) initialises fields when new ClassName() is called. The dot operator accesses fields and methods on an object: sp.x, sp.display(). Objects hide their internal complexity — callers use the interface without needing to know the implementation. Multiple instances from the same class have independent copies of their fields. Arrays of objects are the foundation of particle systems and multi-agent simulations.

Examples

class Spot { float x, y, diameter; void display() { ellipse(x, y, diameter, diameter); } } Spot sp = new Spot(); sp.x = 50; sp.y = 50; sp.diameter = 20; sp.display();

Assessment

Design a Ball class with x, y, vx, vy fields and update() and display() methods; create an array of 20 Ball objects that bounce off the canvas edges.

“Object-oriented programming was developed to make this process more explicit. Object-oriented programming uses objects and classes as building blocks. A class defines a group of methods (functions) and fields (variables).”
corpus · processing-handbook-no-login-mirror-pdf-reas-and-fry · chunk 81