Skip to content

OOP. Not oops

You surely have seen or heard about the taxonomy, the science or technique of classification.
Some concepts are here present too, especially the hierarchical system: and on taxonomy you can rise from the bottom to the top, loosing some particular features of a species to gain a major abstraction until the kingdom. On the opposite, by going down we encounters even less abstract containers, until we get... the objects? No, still classes (intended in a wide way).

Important: a lower level has all features of the higher one, plus its own; and so on. Inheritance!

Now let's come back to code: we have a new information about OOP, the class. It's time to see how to characterize it according to our needs.
With taxonomy we has focused on two aspects: abstraction and inheritance.
From previous articles we have already seen another one: the polymorphism.
Introduced for functions/procedures as overloading, it'll be discussed widely in future to get a major comprehension of it.

What else? A last aspect misses, even if it has been always present from the very first programming lesson: the encapsulation.
In few words it means what is accessible or not from outside.

Do you remember the private and public words always present in TForm definition?
TForm is a class (who inherits from more abstract ones), able to host variables and visual items like buttons (TButton, related class) and functions or procedures like events managers.
These last ones are automatically put inside private area, and the visual items too: nobody forbids us to move them into the public.
In any case be aware that these two areas are not for beauty, but for important functionalities inherent the security of the class's object!

Did you notice we haven't talked about any algorithm? We're concentrated to describe the construction of classes, we're focusing on the who/what!

That's the key! the encapsulation explicates the way the class's object can communicate with the external world (other objects, for example).
[Think to an email login: the system elaborates the password to check its matching with the one present in a database, but the system in no way gives you the possibility to access this function]