What is prototype-based OOP?

Prototype-based programming is a style of object-oriented programming in which inheritance is implemented via process of cloning existing objects that serve as prototypes. There are two methods of constructing new objects: object creation "from nothing" or through cloning an existing object.

In case of creation of a new object everything is simple - if you need a new object, you just write a new object. There is no need to describe future object with class notion, you are describing an object and its behavior at the moment when you are creating it. This is most significant difference from class-based OOP.

When you want to "inherit" object, you clone it from an already existing one. Then you can optionally transform and extend this newly created object to suit your needs. After this you will get both new "subclass" or, better say, "subobject" and new instance of it at the same time.

Prototype-based inheritance

Image source: devdays.com

Short answer

  • Prototype-based programming is a style of OOP when inheritance is implemented via process of cloning existing objects.
  • In class-based OOP inheritance is built around "parent-child" relationship between classes.
  • There are advantages and disadvantages between this two approaches, so consider what suits your needs carefully.

Comments