Getting Started with EK9 · Appendix B

Constructs at a Glance

EK9 has a small family of building blocks. You have met all of them in this book. This appendix puts their capabilities side by side, so you can look up "can a record have methods?" or "does a trait hold state?" in one place.

In the table, $\checkmark$ means "yes, has this"; -- means "no". Read it together with the chapter each construct is taught in, which gives the exact rules.

Construct Fields Methods Operators Constructors Can be abstract Can be extended
Function -- † -- -- -- $\checkmark$ ‡
Program -- -- -- -- -- --
Record $\checkmark$ (public) -- $\checkmark$ $\checkmark$ $\checkmark$ $\checkmark$
Class $\checkmark$ (private) $\checkmark$ $\checkmark$ $\checkmark$ $\checkmark$ $\checkmark$
Trait -- $\checkmark$ $\checkmark$ -- always $\checkmark$
Component $\checkmark$ (private) $\checkmark$ $\checkmark$ $\checkmark$ $\checkmark$ $\checkmark$
Constrained type (its base) (its base) (its base) $\checkmark$ -- -- §
Enumeration fixed members -- compare, text, first/last from text -- --

† A plain function holds no state. The one exception is a dynamic function with a capture list: the captured values become its fields (the second volume).

‡ A function is given an implicit super-type by the compiler so it can be passed around and sorted (the second volume). You reuse behaviour by passing functions, not by subclassing them.

§ A constrained type constrains a base type (Constrained Types). It is not a subtype of its base and cannot be constrained further.

A few things the table cannot show: