Interfaces and Generators

Interfaces, Traits, Iterators and Generators

Classes and Objects built the bookshop's classes one at a time. Here they are joined without a deep inheritance tree: interfaces state what an object can do, traits paste shared code into unrelated classes, and built-in interfaces make objects behave like arrays, strings, JSON and foreach sequences. Generators close the section: they produce values lazily, so a script can walk a million orders in the memory of one.

Subsections