Skip to content

RealyUniqueName/haxe-traits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages