Features of object oriented programming (OOP)



Classes and instances
A class is a template for objects of identical type with similar features. Think as an example of n-dimensional vectors. They have all the same type "vector". Their similarity is
  • that they are given by an ordered set of real numbers (components),
  • that you can apply similar operations like for instance "length" on vectors. The difference here lies only in the number of components you have to square. in that respect, the vectors are similar.
The vector class serves as an abstract model for our concept, what a vector should do, how it should behave (for instance when asked "how long are you ?") and how it should interact with the rest of the environment.

An instance in turn is the actual realization of a class. In our example above it is not "just a vector", but a specific vector with known components. In this respect, classes are "abstract ideas" about objects, and instances are "specific realizations" of object. In terms of programming this translates into the need of programming one class vector, but using different instances of this class.


Variables and methods
Having talked about objects, let us be a little bit more specific about how they work. It turns out that actual objects are specified by variables. In the LEGO example above, these variables could be understood as attributes, like the shape of the piece (brick or wheel or window ? dimensions ? etc.), their colour and so on. So, object carry variables, specifying their actual instance. In the vector case, this could be the number of dimension in which the vector "lives" and the value of the individual components. Hence, classes contain data to be specified when instantiated.
Moreover, the LEGO pieces above behave. They have functionality, like wheels or bricks. Some might have bits to stick together, others might be flat. In the vector case you might thing about functions like length, direction etc. . To realize this functionality, classes provide methods.
In a [first basic example file] I will show how to create a class.
Hints, on how to compile and run this can be found [here].
Some basic syntax questions are answered [here].


[prev] [top]