JavaScript OOP Course 1: Introduction

From WikiMLT
Revision as of 09:32, 18 June 2022 by Spas (talk | contribs) (Стадий: 6 [Фаза:Утвърждаване, Статус:Утвърден]; Категория:JavaScript)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Ref­er­ences

What is OOP

Ob­ject Ori­ent­ed Pro­gram­ming is a pro­gram­ming par­a­digm (or style of pro­gram­ming) cen­tered around Ob­jects rather than Func­tions.

Four Pil­lars of OOP

The four core con­cepts of Ob­ject Ori­ent­ed Pro­gram­ming:

1. En­cap­su­la­tion – OOP comes to solve the spaghet­ti prob­lem of the func­tion ori­en­tat­ed pro­gram­ming. OOP com­bine a group of re­lat­ed vari­ables and func­tions in­to in­to a unit and we call that unit Ob­ject. The Object's vari­ables are called Prop­er­ties and the Object's func­tions are called Meth­ods.

2. Ab­strac­tion – hide the com­plex­i­ty in­side the Ob­ject and cre­ate a sim­ple in­ter­face with on­ly few Prop­er­ties and Meth­ods to in­ter­act with. Thus we can re­duce the im­pact of change of the in­ter­nal Object's log­ic.

3. In­her­i­tance – it al­lows (helps) you to elim­i­nate re­dun­dant code. In OOP we can de­fine some Prop­er­ties and Meth­ods in­to a gener­ic ob­ject and have may Ob­jects in­her­it­ed these (gener­ic) Prop­er­ties and Meth­ods.

4. Poly­mor­phismpoly means many and morph means form => so poly­mor­phism means many forms. In OOP poly­mor­phism is a tech­nique that al­lows you to get rid of long if and else or switch and case state­ments. For ex­am­ple with­in the gener­ic Ob­ject we can de­fine one method that will be­have dif­fer­ent­ly de­pend­ing of the type of the Ob­ject we have ref­er­enc­ing.

The ben­e­fits of of Ob­ject Ori­ent­ed Pro­gram­ming:

1. With the En­cap­su­la­tion we group re­lat­ed vari­ables and func­tions to­geth­er and in this way we can re­duce the com­plex­i­ty. We can reuse the ob­jects in dif­fer­ent parts of a pro­gram or in dif­fer­ent pro­grams. This method re­duces the com­plex­i­ty and in­crease the reusabil­i­ty.

2. With the Ab­strac­tion we can hide the de­tails and com­plex­i­ty and show on­ly the es­sen­tials . This method re­duces the com­plex­i­ty and iso­late the im­pact of changes of the code.

3. With the In­her­i­tance we can elim­i­nate the re­dun­dant code.

4. With the Poly­mor­phism we can refac­tor the ug­ly switch/​​​case state­ments.