Let's start with a quick introduction to object orientation and
the fundamental concepts behind it. And let's start by discussing what
exactly is object orientation? If you're younger than me, it
could be that the first programming language you learned was already
an object-oriented language. But things were not always like this.
Before object orientation became prevalent, people were not used to thinking
in terms of objects. So what happened afterwards? And what does
it mean to think in terms of objects and to follow
an object-oriented approach? First of all, it
means to give precedence of data over function.
Did items rather than functionality become the center
of development activities. This also allows for enforcing
the very important concept of information hiding,
which is the encapsulation and segregation of data
behind well-defined and ideally stable interfaces. In order
to be able to hide the design and
also implementation decisions. And note that the terms
encapsulation and information hiding are often used interchangeably, although
some people prefer to think of information hiding
as being the principle and encapsulation being the technique
to achieve information hiding. The key concept though,
no matter which term you use, is really to
gather, to seclude this data behind sort of
a wall and give access to the data only
through interfaces that you, the developer define. And why is
that important? Oh, for many reasons, and one of the main
ones is that it makes code more maintainable. Because the
rest of the code, the rest of the system doesn't have
to be concerned on how the implementation details or the
design are defined. And therefore, any change that happens behind this
wall doesn't concern the rest of the system. And, doesn't
affect the rest of the system, as long as you keep
your interfaces consistent. Another advantage of focusing on
objects and encapsulating the information into cohesive entities is
that it allows the reuse of object definitions
by incremental refinement. Which is what we normally call
inheritance. And inheritance is definitely a fundamental concept
in object orientation. For example, we can define a
car as a refinement of the vehicle. That there's
some additional characteristics with respect to a generic vehicle.
And then we can use the car wherever a vehicle can be used, which is what we
call polymorphism. And we'll continue this discussion for a
very long time. Because there's so many things that
could be discussed when we talk about object orientation,
its characteristics and its advantages. But in the interest
of time, let's for now just stop here. And
start talking about two key concepts in object orientation.