TRANSCRIPCIÓNEnglish

Object-Oriented Programming, Simplified

7m 35s1,181 palabras181 segmentsEnglish

TRANSCRIPCIÓN COMPLETA

0:00

[Music]

0:00

a popular interview question concerns

0:04

the four core concepts in

0:05

object-oriented programming this

0:08

concepts are encapsulation abstraction

0:11

inheritance and polymorphism let's look

0:15

at each of these concepts before

0:17

object-oriented programming we had

0:19

procedure of programming that divided a

0:21

program into a set of functions so we

0:23

have data stored in a bunch of variables

0:26

and functions that operate on the data

0:28

this style of programming is very simple

0:31

and straightforward often it's what you

0:33

learn as part of your first programming

0:36

subject at a university but as your

0:38

programs grow it will end up with a

0:40

bunch of functions that are all over the

0:42

place you might find yourself copying

0:44

and pasting lines of code over and over

0:47

you make a change to one function and

0:49

then several other functions break

0:51

that's what we call spaghetti code there

0:54

is so much interdependence e between all

0:56

these functions it becomes problematic

0:59

object-oriented programming came to

1:01

solve this problem in object-oriented

1:03

programming we combine a group of

1:05

related variables and functions into a

1:07

unit we call that unit an object we

1:11

refer to these variables as properties

1:13

and the functions as methods here's an

1:16

example think of a car a car is an

1:20

object with properties such as make

1:22

model and color and methods like start

1:25

stop and move now you might say what

1:29

marche

1:29

we don't have cars in our programs give

1:31

me a real programming example ok think

1:34

of the local storage object in your

1:36

browser's every browser has a local

1:39

storage object that allows you to store

1:42

data locally this local storage object

1:45

has a property like length which returns

1:47

the number of objects in the storage and

1:49

metals like set item and remove item so

1:53

in object-oriented programming we group

1:55

related variables and functions that

1:57

operate on them into objects and this is

2:00

what we call encapsulation let me show

2:03

you an example of this in action so here

2:06

we have three variables base salary over

2:09

time and rate below these we have a

2:12

function

2:12

to calculate the wage for an employee we

2:15

refer to this kind of implementation as

2:17

procedural so we have variables on one

2:20

side and functions on the other side

2:22

they're hard decoupled now let's take a

2:25

look at the object-oriented way to solve

2:27

this problem we can have an employee

2:29

object with three properties a salary

2:32

over time and rate and a method called

2:35

get wage now why is this better well

2:38

first of all look at the get wage

2:40

function this function has no parameters

2:43

in contrast in a procedural example our

2:47

get wage function has three parameters

2:49

the reason in this implementation we

2:52

don't have any parameters is because all

2:54

these parameters are actually modeled as

2:56

properties of this object all these

3:00

properties and the get wage function

3:02

they are highly related so they are part

3:04

of one unit so one of the symptoms of

3:06

procedural code is functions with so

3:09

many parameters when you write code in

3:12

an object-oriented way your functions

3:14

end up having fewer and fewer parameters

3:16

as Uncle Bob says the best functions are

3:20

those with no parameters the fewer the

3:22

number of parameters the easier it is to

3:24

use and maintain that function so that's

3:27

encapsulation now let's look at

3:29

abstraction think of a DVD player as an

3:32

object this DVD player has a complex

3:35

logic board on the inside and a few

3:38

buttons on the outside that you interact

3:40

with you simply press the play button

3:42

and you don't care what happens on the

3:44

inside all that complexity is hidden

3:47

from you this is abstraction in practice

3:49

we can use the same technique in our

3:52

objects so we can hide some of the

3:54

properties and methods from the outside

3:56

and this gives us a couple of benefits

3:59

first is that we'll make the interface

4:01

of those objects simpler using an

4:04

understanding an object with a few

4:06

properties and methods is easier than an

4:08

object with several properties and

4:11

methods the second benefit is that it

4:14

helps us reduce the impact of change

4:16

let's imagine that tomorrow we change

4:19

these inner or private methods

4:22

these changes will leak to the outside

4:24

because we don't have any code that

4:26

touches these methods outside of their

4:28

containing object we may delete a method

4:31

or change its parameters but none of

4:33

these changes will impact the rest of

4:35

the applications code so with

4:38

abstraction we reduce the impact of

4:40

change now the third core concept in

4:43

object-oriented programming inheritance

4:45

inheritance is a mechanism that allows

4:48

you to eliminate redundant code here's

4:51

an example think of HTML elements like

4:54

text boxes drop-down lists checkboxes

4:57

and so on

4:58

all these elements have a few things in

5:00

common they should have properties like

5:02

hidden and inner HTML and metals like

5:05

click and focus instead of redefining

5:08

all these properties and methods for

5:10

every type of HTML element we can define

5:14

them once in a generic object call it

5:16

HTML element and have other objects

5:19

inherit these properties and methods so

5:22

inheritance helps us eliminate redundant

5:25

code and finally polymorphism poly means

5:29

many more means form so polymorphism

5:33

means many forms in object-oriented

5:36

programming polymorphism is a technique

5:38

that allows you to get rid of long

5:41

ethanol's

5:42

or switch and case statements so back to

5:45

our HTML elements example all these

5:48

objects should have the ability to be

5:50

rendered on a page but the way each

5:52

element is rendered is different from

5:54

the others if you want to render

5:56

multiple HTML elements in a procedural

5:59

way our code would probably look like

6:01

this but with object orientation we can

6:04

implement a render method in each of

6:07

these objects and the render method will

6:09

behave differently depending on the type

6:12

of the object you're referencing so we

6:15

can get rid of this nasty switch and

6:17

case and use one line of code like this

6:19

you will see that later in the course so

6:22

here are the benefits of object oriented

6:25

programming using encapsulation we group

6:27

related variables and functions together

6:30

and this way we can reduce complexity

6:33

now we can reuse this object and do

6:36

from parts of a program or in different

6:38

programs with abstraction we hide the

6:41

details and the complexity and show only

6:44

the essentials this technique reduces

6:46

complexity and also isolates the impact

6:50

of changes in the code with inheritance

6:52

we can eliminate redundant code and with

6:55

polymorphism we can refactor ugly switch

6:58

case statements

7:03

well hello it's me mash again I wanted

7:06

to say thank you very much for watching

7:08

this tutorial to the end I hope you

7:10

learned a lot please share and like this

7:12

video to support me if you want to learn

7:14

more about the object-oriented

7:15

programming as I told you before I have

7:17

a course called object-oriented

7:19

programming in JavaScript if you want to

7:21

learn more click on the link in the

7:23

video description and enroll in the

7:24

course if not that's perfectly fine make

7:27

sure to subscribe to my channel because

7:29

I upload new videos every week thank you

7:32

and have a great day

DESBLOQUEAR MÁS

Regístrate gratis para acceder a funciones premium

VISOR INTERACTIVO

Mira el video con subtítulos sincronizados, superposición ajustable y control total de la reproducción.

REGÍSTRATE GRATIS PARA DESBLOQUEAR

RESUMEN DE IA

Obtén un resumen instantáneo generado por IA del contenido del video, los puntos clave y las conclusiones.

REGÍSTRATE GRATIS PARA DESBLOQUEAR

TRADUCIR

Traduce la transcripción a más de 100 idiomas con un solo clic. Descarga en cualquier formato.

REGÍSTRATE GRATIS PARA DESBLOQUEAR

MAPA MENTAL

Visualiza la transcripción como un mapa mental interactivo. Comprende la estructura de un vistazo.

REGÍSTRATE GRATIS PARA DESBLOQUEAR

CHATEA CON LA TRANSCRIPCIÓN

Haz preguntas sobre el contenido del video. Obtén respuestas impulsadas por IA directamente desde la transcripción.

REGÍSTRATE GRATIS PARA DESBLOQUEAR

SACA MÁS PARTIDO A TUS TRANSCRIPCIONES

Regístrate gratis y desbloquea el visor interactivo, los resúmenes de IA, las traducciones, los mapas mentales y mucho más. No se requiere tarjeta de crédito.

    Object-Oriented… - Transcripción Completa | YouTubeTranscript.dev