I'm a JS Subject Matter Expert (SME) that has spent the past few years spearheading curricula and teaching initiatives at colleges and bootcamps, in person and virtually.
The prototypal inheritance does offer some potential advantages and does differ from 'classical inheritance.
For example, in classical OOP, we have to deal with interfaces and other complexity just do something like is shown where rude can easily implement the functionality 'on the fly' to a specific instance - in line of code.
I welcome you to write a formal article showing similar examples with 'purely classical' inheritance, as I don't profess to be any type of expert in 'classical OOP.'
In one of my next posts, I will focus on not necessarily needing to do anything OOP and use composition instead.
This old, but gr8 video kind of sets the table for that:
.
For example, in classical OOP, we have to deal with interfaces
We only have to deal with interfaces when they are implemented as an entry to a function or method.
Consider this in C#
// Classes have implicit interface definitions// plus the ability to create a new object of that typepublicclassPerson{// implicit interface properties of...stringlastName;stringfirstName;}// if there's a method anywhere in the project like this:setName(Personperson){// the parameter is a concrete Person object// that has implicit interfaces of lastName and firstName properties.}// but what about this?setName(iPersonperson){}// and assume this:// a definition of an interfaceinterfaceIPerson{stringlastName;stringfirstName;}// here we have the same exact thing happening, // but the parameter is asking for an object of type interface// and not a concrete person object.// The only difference is that we cannot create a new instance of an interface. // To do that we'd need this.// Change Person to implement the interfaceclassPerson:IPerson{stringlastName;stringfirstName;}//create a new person object which passes the interface testvarperson=newPerson()// Works due to our Person Class// implementation of iPersonsetName(iPersonperson){}
Sound confusing? Why would we do this on just a person model class? Answer: We wouldn't, because the Person class with just 2 properties is sufficient and the interface is implicit.
There's two types of inheritance 'classical' which is vertical nature, it deals with classes, and subclasses. The interface (explicit or implicit) is 'horizontal in nature' and is seen as the ability to pass something in to be contained, it can be done via parameters or by object placeholders with the class or function. The concepts of composition use the horizontal style while classical inheritance is the vertical style.
It all boils down to one simple concept, can I morph my object in such a way that I can only see the properties or functions I want? If the answer is yes then we are using some form on inheritance/composition.
BTW, I saw that video years ago and disagreed with the general conclusions then.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The prototypal inheritance does offer some potential advantages and does differ from 'classical inheritance.
For example, in classical OOP, we have to deal with interfaces and other complexity just do something like is shown where
rude
can easily implement the functionality 'on the fly' to a specific instance - in line of code.I welcome you to write a formal article showing similar examples with 'purely classical' inheritance, as I don't profess to be any type of expert in 'classical OOP.'
In one of my next posts, I will focus on not necessarily needing to do anything OOP and use composition instead.
This old, but gr8 video kind of sets the table for that: .
Sound confusing? Why would we do this on just a person model class? Answer: We wouldn't, because the Person class with just 2 properties is sufficient and the interface is implicit.
There's two types of inheritance 'classical' which is vertical nature, it deals with classes, and subclasses. The interface (explicit or implicit) is 'horizontal in nature' and is seen as the ability to pass something in to be contained, it can be done via parameters or by object placeholders with the class or function. The concepts of composition use the horizontal style while classical inheritance is the vertical style.
It all boils down to one simple concept, can I morph my object in such a way that I can only see the properties or functions I want? If the answer is yes then we are using some form on inheritance/composition.
BTW, I saw that video years ago and disagreed with the general conclusions then.