there are two types of interface types: - "open interfaces", like in Java and C# -- (classes is a superset of interfaces, so most OO languages have them) - "closed interfaces", e.g. a union with a "kind" flag performance wise: - data memory usage should be about the same (implementation pointer vs. implementation enum value) - enum value should result in faster usage (no indirect lookup via vtable, no pointer call) - instanceof operation is also faster here is a sample of a closed interface (or class tree, perhaps) type Set = classtree of Iterable ( HashSet LinkedHashSet Tree ) Set is now a struct that begins with an enum, and has an unknown size (so any Set variable must be a ref/rwref/wref) mixed-closed-open inteface: type Set = classtree of Iterable ( CustomSet HashSet LinkedHashSet TreeSet ) syntax: openinterface Iterable { func iterator(ref this) return shared(this) Iterator # ^ tricky! # an internal struct type is created so the interface can # also be passed around (as a reference) } openinterface Iterator { func has_next(ref this) return bool func next(rwref this) return dedup ref T # ^ tricky! } classtree Set extends Iterable { CustomSet HashSet LinkedHashSet TreeSet size elemsize = sizeof T; # ^ tricky! func add(rwref this, dedup ref takeown T elem) return bool # ^ tricky! func contains(ref this, dedup ref T elem) return bool func remove(rwref this, dedup ref dropown T elem) return bool func count(ref this) return size func clear(wref this) when is_dedup T # ^ tricky! #interface func iterator(ref this) return takeshare(this) SetIterator # # ^ tricky! # An internal function for the interface should also be generated, # which fills a struct with pointers to the implementation functions func _LRL_get_iface_Iterable(ref this, wref _LRL_iface_Iterable iface) } classtree SetIterator extends Iterator { CustomSetIterator HashSetIterator LinkedHashSetIterator TreeSetIterator size elemsize = sizeof T ref Set #interface func has_next(ref this) return bool #interface func next(rwref this) return dedup ref T }