zaxebo1 / haxe-traits

[DEPRECATED] Traits for Haxe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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!"
    }
}

About

[DEPRECATED] Traits for Haxe


Languages

Language:Haxe 100.0%