Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Composure can be installed via haxelib using the commandline: haxelib install composure-hx
Introducing Composure for Haxe (with Dependency Injection)
Class inheritance is massively overused by developers, and by replacing it with a solid composition design, a lot of code becomes a lot more reusable.
Some languages and platforms have native support for composition (e.g. Unity3D), but for AS3/Haxe there was nothing, so about two years ago I built a lightweight composition framework for AS3 called Composure, I’ve recently completely rebuilt it for Haxe, utilising Haxe’s awesome typing and macro systems to make this small library really powerful.
From Inheritance to Composition
Those familiar with Unity3D will be familiar with GameObjects and Components, the two core building blocks used to build things. In Composure these two core types are known as ComposeGroups and Traits.
Each conceptual item in your game/app will be a ComposeGroup, with a bunch of Traits attached to it. Any time while your app is running these traits can be added/remove, changing the behaviour of on object completely. Say, for example, you have a player’s character on-screen and wish to switch from the user controlling the character to computer control, you would simply remove your MouseKeyboardControllerTrait and replace it with a ComputerControllerTrait.
These ComposeGroups must be added to the ComposeRoot object to be active, and can also be parented to other ComposeGroup objects (forming a heirarchy).