Inheritance and overrides
Inheritance lets a child class reuse and specialize a parent class. Craftly supports one parent class per class, plus multiple implemented interfaces.
Establish a parent
Section titled “Establish a parent”Open /plot classes → child class → Class Structure and choose its parent. The parent must permit inheritance: a Final or Static class cannot be extended. Inheritance must remain acyclic.
For example, Reward can define a public instance method Describe returning String, and CoinReward can extend Reward with an additional Number field amount.
Reuse fields and methods
Section titled “Reuse fields and methods”Fields are inherited by stable identity. Use unique field names through the chain. Public members remain callable where types match; Protected members are available to the owner/subclasses; Private members remain limited to their declaring class.
A child object may be stored in a compatible parent-typed Variable. That does not expose child-only methods through the parent’s declared type. Collections remain invariant: this compatibility does not make List<CoinReward> assignable to List<Reward>.
Override a method
Section titled “Override a method”- Define the same instance-method signature on the child class.
- Enable Override in Method Settings.
- Preserve compatible result type, access, and async contract.
- Provide the child body and compile.
Calling the method dispatches using the object’s actual runtime class. A Reward Variable containing a CoinReward therefore runs the CoinReward override when the signature is overridden.
A same-name method with different parameter types is an overload, not an override. Final methods cannot be overridden; a final static method cannot be hidden with the same signature. Different-parameter overloads can remain valid.
Call the parent implementation
Section titled “Call the parent implementation”Use Call Method’s Parent Object target from a valid child context. This explicitly invokes the parent’s implementation instead of redispatching to the current override. Use it to extend behavior without duplicating the parent’s whole body.
Constructors and abstract classes
Section titled “Constructors and abstract classes”Parent construction happens first. Satisfy the parent’s constructor requirements before using child state. Abstract classes can declare behavior and serve as variable types but cannot be instantiated. Concrete children must fulfill inherited abstract/interface contracts.
See contracts for interfaces and abstract declarations, and copying for how parent/child objects retain identity.