User:Kore sar/sandbox

In object-oriented programming, a stamp is a composable factory function (not to be confused with function composition). Stamps allow you to inherit from multiple ancestors by composing multiple source stamps. You can combine properties, methods, and initializers (with closures) from any number of stamps to produce a new stamp.

Motivation
Stamps are more flexible than traditional factory functions or classical multiple inheritance. Traditional factory functions can't be composed together to produce new factory functions. Class inheritance does not provide a standardized mechanism for class composition.

Stamp composition takes advantage of three different kinds of prototypal inheritance:


 * Differential inheritance, aka delegation (e.g., JavaScript's Prototype),
 * Mixins/cloning with optional deep merge, as known as concatenative inheritance (e.g., JavaScript's Object.assign),
 * Functional / closure inheritance (for initialization or privacy/encapsulation)

Difference from Classes

 * It's easy to compose (see composition over inheritance) multiple stamps to create a new stamp with all of the source stamp capabilities
 * Stamps are factory functions, so they don't need to be invoked with the new keyword (which couples callers to the implementation of object instantiation)
 * Stamps don't create parent-child class hierarchies. Class hierarchies create "is-a" relationships between classes. Stamp composition creates "has-a" or "uses-a" relationships, instead. For that reason, stamp inheritance is less brittle than class inheritance.