Skip to content

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.

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.

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>.

  1. Define the same instance-method signature on the child class.
  2. Enable Override in Method Settings.
  3. Preserve compatible result type, access, and async contract.
  4. 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.

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.

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.