O
optimistx
There are numerous examples about trying to implement classical inheritance
in javascript. Most authors seem to take for granted that classical
inheritance or simulating it is necessary in any language, incl javascript.
I am ashamed to confess that in spite of about 15 years of using object
oriented languages in my hobbies I am not really convinced about the
usefulness of inheriting. May be that if somebody makes a set of programs
for others to inherit from the idea might be practical. Is it so that
inheritance is needed and useful in big projects, with tens or hundreds of
people coding? But designing class inheritance is waste of energy when
writing some internet pages alone or together with some friends?
The educational examples are about animals, cats and dogs, or persons
becoming employees and managers, or shapes on the screen becoming
rectangles, circles, or vehicles becoming cars and sports cars. But
something bothers me all the time with these examples: why not make those
objects directly without wrestling with inheritance code like
function extend(B, A) {
Intermediate = function (){};
Intermediate.prototype = A.prototype;
B.prototype = new Intermediate();
B.prototype.constructor = B;
B.parentConstructor = A;
}
I would like to see a simple and useful example about classical inheritance
in any language. Convince myself that inheritance there saves from writing
repeated code or helps in maintaining or understanding the situation. After
that I would try to see, how that example could be written in prototypal
language javascript, with simulated classical inheritance or using the
natural features of prototypal language.
When it is possible to add, delete, replace methods and other properties in
the objects using constructor functions simply to do that, why wrestle with
mysterious and astounding features in 'inheritance'? Is the reason simply
that programmers have learnt that inheritance in C++, Java etc must be good
for their health (although they might not be se sure about that: eat more
sallad, I'll eat...).
Peter Michaux has presented an example about subject-observer patterns and
showed some variants to solve that in 'javascript-way' instead of classical
(?) .
http://peter.michaux.ca/articles/transitioning-from-java-classes-to-javascript-prototypes
There are some astounding sentences/references there like 'Java classes are
a mistake ' (or something like that).
I have to play and learn about this example. In the meantime, can you give
links to examples which have convinced you about the usefulness of classical
inheritance?
in javascript. Most authors seem to take for granted that classical
inheritance or simulating it is necessary in any language, incl javascript.
I am ashamed to confess that in spite of about 15 years of using object
oriented languages in my hobbies I am not really convinced about the
usefulness of inheriting. May be that if somebody makes a set of programs
for others to inherit from the idea might be practical. Is it so that
inheritance is needed and useful in big projects, with tens or hundreds of
people coding? But designing class inheritance is waste of energy when
writing some internet pages alone or together with some friends?
The educational examples are about animals, cats and dogs, or persons
becoming employees and managers, or shapes on the screen becoming
rectangles, circles, or vehicles becoming cars and sports cars. But
something bothers me all the time with these examples: why not make those
objects directly without wrestling with inheritance code like
function extend(B, A) {
Intermediate = function (){};
Intermediate.prototype = A.prototype;
B.prototype = new Intermediate();
B.prototype.constructor = B;
B.parentConstructor = A;
}
I would like to see a simple and useful example about classical inheritance
in any language. Convince myself that inheritance there saves from writing
repeated code or helps in maintaining or understanding the situation. After
that I would try to see, how that example could be written in prototypal
language javascript, with simulated classical inheritance or using the
natural features of prototypal language.
When it is possible to add, delete, replace methods and other properties in
the objects using constructor functions simply to do that, why wrestle with
mysterious and astounding features in 'inheritance'? Is the reason simply
that programmers have learnt that inheritance in C++, Java etc must be good
for their health (although they might not be se sure about that: eat more
sallad, I'll eat...).
Peter Michaux has presented an example about subject-observer patterns and
showed some variants to solve that in 'javascript-way' instead of classical
(?) .
http://peter.michaux.ca/articles/transitioning-from-java-classes-to-javascript-prototypes
There are some astounding sentences/references there like 'Java classes are
a mistake ' (or something like that).
I have to play and learn about this example. In the meantime, can you give
links to examples which have convinced you about the usefulness of classical
inheritance?