Object-Oriented Programming, Simplified
TRANSCRIPTION COMPLÈTE
[Music]
a popular interview question concerns
the four core concepts in
object-oriented programming this
concepts are encapsulation abstraction
inheritance and polymorphism let's look
at each of these concepts before
object-oriented programming we had
procedure of programming that divided a
program into a set of functions so we
have data stored in a bunch of variables
and functions that operate on the data
this style of programming is very simple
and straightforward often it's what you
learn as part of your first programming
subject at a university but as your
programs grow it will end up with a
bunch of functions that are all over the
place you might find yourself copying
and pasting lines of code over and over
you make a change to one function and
then several other functions break
that's what we call spaghetti code there
is so much interdependence e between all
these functions it becomes problematic
object-oriented programming came to
solve this problem in object-oriented
programming we combine a group of
related variables and functions into a
unit we call that unit an object we
refer to these variables as properties
and the functions as methods here's an
example think of a car a car is an
object with properties such as make
model and color and methods like start
stop and move now you might say what
marche
we don't have cars in our programs give
me a real programming example ok think
of the local storage object in your
browser's every browser has a local
storage object that allows you to store
data locally this local storage object
has a property like length which returns
the number of objects in the storage and
metals like set item and remove item so
in object-oriented programming we group
related variables and functions that
operate on them into objects and this is
what we call encapsulation let me show
you an example of this in action so here
we have three variables base salary over
time and rate below these we have a
function
to calculate the wage for an employee we
refer to this kind of implementation as
procedural so we have variables on one
side and functions on the other side
they're hard decoupled now let's take a
look at the object-oriented way to solve
this problem we can have an employee
object with three properties a salary
over time and rate and a method called
get wage now why is this better well
first of all look at the get wage
function this function has no parameters
in contrast in a procedural example our
get wage function has three parameters
the reason in this implementation we
don't have any parameters is because all
these parameters are actually modeled as
properties of this object all these
properties and the get wage function
they are highly related so they are part
of one unit so one of the symptoms of
procedural code is functions with so
many parameters when you write code in
an object-oriented way your functions
end up having fewer and fewer parameters
as Uncle Bob says the best functions are
those with no parameters the fewer the
number of parameters the easier it is to
use and maintain that function so that's
encapsulation now let's look at
abstraction think of a DVD player as an
object this DVD player has a complex
logic board on the inside and a few
buttons on the outside that you interact
with you simply press the play button
and you don't care what happens on the
inside all that complexity is hidden
from you this is abstraction in practice
we can use the same technique in our
objects so we can hide some of the
properties and methods from the outside
and this gives us a couple of benefits
first is that we'll make the interface
of those objects simpler using an
understanding an object with a few
properties and methods is easier than an
object with several properties and
methods the second benefit is that it
helps us reduce the impact of change
let's imagine that tomorrow we change
these inner or private methods
these changes will leak to the outside
because we don't have any code that
touches these methods outside of their
containing object we may delete a method
or change its parameters but none of
these changes will impact the rest of
the applications code so with
abstraction we reduce the impact of
change now the third core concept in
object-oriented programming inheritance
inheritance is a mechanism that allows
you to eliminate redundant code here's
an example think of HTML elements like
text boxes drop-down lists checkboxes
and so on
all these elements have a few things in
common they should have properties like
hidden and inner HTML and metals like
click and focus instead of redefining
all these properties and methods for
every type of HTML element we can define
them once in a generic object call it
HTML element and have other objects
inherit these properties and methods so
inheritance helps us eliminate redundant
code and finally polymorphism poly means
many more means form so polymorphism
means many forms in object-oriented
programming polymorphism is a technique
that allows you to get rid of long
ethanol's
or switch and case statements so back to
our HTML elements example all these
objects should have the ability to be
rendered on a page but the way each
element is rendered is different from
the others if you want to render
multiple HTML elements in a procedural
way our code would probably look like
this but with object orientation we can
implement a render method in each of
these objects and the render method will
behave differently depending on the type
of the object you're referencing so we
can get rid of this nasty switch and
case and use one line of code like this
you will see that later in the course so
here are the benefits of object oriented
programming using encapsulation we group
related variables and functions together
and this way we can reduce complexity
now we can reuse this object and do
from parts of a program or in different
programs with abstraction we hide the
details and the complexity and show only
the essentials this technique reduces
complexity and also isolates the impact
of changes in the code with inheritance
we can eliminate redundant code and with
polymorphism we can refactor ugly switch
case statements
well hello it's me mash again I wanted
to say thank you very much for watching
this tutorial to the end I hope you
learned a lot please share and like this
video to support me if you want to learn
more about the object-oriented
programming as I told you before I have
a course called object-oriented
programming in JavaScript if you want to
learn more click on the link in the
video description and enroll in the
course if not that's perfectly fine make
sure to subscribe to my channel because
I upload new videos every week thank you
and have a great day
DÉBLOQUER PLUS
Inscrivez-vous gratuitement pour accéder aux fonctionnalités premium
VISUALISEUR INTERACTIF
Regardez la vidéo avec des sous-titres synchronisés, une superposition réglable et un contrôle total de la lecture.
RÉSUMÉ IA
Obtenez un résumé instantané généré par l'IA du contenu de la vidéo, des points clés et des principaux enseignements.
TRADUIRE
Traduisez la transcription dans plus de 100 langues en un seul clic. Téléchargez dans n'importe quel format.
CARTE MENTALE
Visualisez la transcription sous forme de carte mentale interactive. Comprenez la structure en un coup d'œil.
DISCUTER AVEC LA TRANSCRIPTION
Posez des questions sur le contenu de la vidéo. Obtenez des réponses alimentées par l'IA directement à partir de la transcription.
TIREZ LE MEILLEUR PARTI DE VOS TRANSCRIPTIONS
Inscrivez-vous gratuitement et débloquez la visionneuse interactive, les résumés IA, les traductions, les cartes mentales, et plus encore. Aucune carte de crédit requise.