Skip to content

Instantly share code, notes, and snippets.

@mamarjan
Created June 10, 2012 11:55
Show Gist options
  • Save mamarjan/2905145 to your computer and use it in GitHub Desktop.
Save mamarjan/2905145 to your computer and use it in GitHub Desktop.
Methods chaining pattern
mixin template Identity()
{
uint id = ID_UNKNOWN;
string name = NAME_UNKNOWN;
this() { }
auto set_id(uint new_id) { this.id = new_id; return this; }
auto set_name(string new_name) { this.name = new_name; return this; }
}
mixin template MarkerInfo() {
mixin Identity;
mixin Attributes;
Chromosome chromosome = null; /// Reference to Chromosome
Position position = MARKER_POSITION_UNKNOWN; /// Marker position - content depends on map
auto set_position(double new_position) { position = new_position; return this; }
auto set_chromosome(Chromosome new_chromosome) { chromosome = new_chromosome; return this; }
}
class Marker {
mixin MarkerInfo;
}
Marker m = (new Marker()).set_id(id).set_name(name).set_position(pos).set_chromosome(chrom);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment