What are the advantages that prototype based OO has over class based OO?

前端 未结 7 1460
借酒劲吻你
借酒劲吻你 2020-11-30 23:18

Why is class based OO so popular instead of prototype based OO? Do they teach the latter in schools? Though Javascript is prototype based, most people use it mostly function

7条回答
  •  独厮守ぢ
    2020-11-30 23:56

    This question had me intrigued so I went back and read some of the original papers on the concept. It appears to have begun in the mid-1980s in the Smalltalk world but eventually became one of the founding principals of Self. Much later Javascript also adopted it.

    The argument put forth in the papers is that it is easier to learn. There is really no technical benefit proposed other than learning. The papers all explain how it is just as expressive as a class-based language but much easier to learn. People naturally think about things in a concrete manner rather than in the abstract. We think of the elephant we saw at the zoo, not a generic "elephant". When we see other elephants, we classify them as differences from the first one. A prototype-based language facilitates this thinking. Think of it as programming by differential.

    Is that a sufficient reason to use it in a language? Perhaps. In the 25 years since the idea first started percolating, I would argue that abstracted concepts like class-based OO has not been too hard for most people to learn. On the other hand perhaps there is a need for a blue-collar programming language (like Javascript) which is easier and this may be a way to accomplish that.

    If interested, you might start with this paper about self.

提交回复
热议问题