Created
June 10, 2012 11:55
-
-
Save mamarjan/2905145 to your computer and use it in GitHub Desktop.
Methods chaining pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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