[DEPRECATED] Traits for Haxe
Haxe
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
src/traits
.gitignore
README.md
haxelib.json static fields inheritance for normal extending classes with traits Oct 31, 2013

README.md

DEPRECATED

It is not recommended to use this project anymore. Use tink_lang instead.

Traits for Haxe

This macro allows to reuse code in different classes, which can't extend each other.

Features:

  • Static vars / methods inheritance (even inlined).
  • Multiple inheritance
  • "Lazy" interfaces: traits methods are copied to descendant class, so you don't need to write implementation in each class, which implements trait. But you still can skip implementation of some methods in trait to force each descendant implement these methods (It's a sort of "classic" abstracts from Java or PHP)
  • Ability to "override" trait's methods

Hints:

Installation:

haxelib install traits

Basic example:

interface TWorker extends traits.ITrait{
    public function work() : Void {
        trace("I'm working!");
    }
}
interface TReader extends traits.ITrait{
    public function read() : Void {
        trace("I'm reading!");
    }
}
class Test implements TWorker implements TReader {
    public function new() : Void {
        this.work(); //output: "I'm working!"
        this.read(); //output: "I'm reading!"
    }
}