Objects - Why?
Objects provide a more natural model of the world. Programs are easier to
understand. c3 = c1 + c2 is how we are used to manipulating vectors
in formulae. CALL VADD(C1,C2,C3,2) doesn't make sense.
Creation and destruction of objects is done in a controlled way so
program initialisation and termination can be less error-prone. The compiler
rejects the statement
because there is no initialiser.
Type safety extends to manipulations on objects. The compiler rejects
Vector2 c4 = c1 + "OUCH!!!";
because there is no Vector2 addition operator having an argument
of type string.
Illegal or inappropriate use of the data is protected. The
compiler would reject the syntactically legal statement
c3.v = c1.v * c2.v;
User code does not have direct access to the vector elements unless the
programmer allows it.
Using objects leads to more modular programs.