There are two ways to implement object-oriented inheritance in e: like inheritance and when inheritance
Like
Like inheritance is the classical, single inheritance familiar to users of all object-oriented languages and is specified with the like clause in new struct definitions.
EXAMPLE: <'
struct exam { from_exam()is{ out("This is BASE"); };
};
struct e_exam like exam{ from_exam()isonly{ out("This is EXTENDED");
When inheritance is a concept unique to e and is specified by defining subtypes with when struct members. When inheritance provides the following advantages compared to like inheritance:
-Ability to have explicit reference to the when fields
-Ability to have multiple, orthogonal subtypes
-Ability to extend the struct later
EXAMPLE:when <'
type pack_kind :[long, short]; struct packet { kind: pack_kind; when long packet { a: int; }; check_my_type()is{ if meis a long packet (l){ print l; }; if meis not a long packet { print kind; }; }; }; extend sys { p:packet; run()isalso{ p.check_my_type(); } }; '> RESULT
l = packet-@0: packet --------------------------------------------------@test 0 kind: long 1 long'a: 2129590818