Created
August 18, 2016 02:53
-
-
Save neo125874/fb23fc89435c43392fdeb2112aeea754 to your computer and use it in GitHub Desktop.
fluent interface implementation example
This file contains hidden or 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
public class WeightedModel { | |
private WeightedModel() { | |
_set = new WeightedModelFluentInterface(this); | |
} | |
public static WeightedModelFluentInterface Create() { | |
return new WeightedModel().Set; | |
} | |
private WeightedModelFluentInterface Set | |
{ | |
get { return _set; } | |
} | |
private readonly WeightedModelFluentInterface _set; | |
private Dictionary<string, Tuple<int, int>> _modelWithWeight = new Dictionary<string, Tuple<int, int>>(); | |
public class WeightedModelFluentInterface { | |
private readonly WeightedModel _weightedModel; | |
public WeightedModelFluentInterface(WeightedModel weightedModel) { | |
_weightedModel = weightedModel; | |
} | |
public WeightedModelFluentInterface SetaaaModel(int posWeight, int negWeight) { | |
_weightedModel.ModelWithWeight["aaa"] = Tuple.Create(posWeight, negWeight); | |
return this; | |
} | |
public WeightedModelFluentInterface SetbbbModel(int posWeight, int negWeight) | |
{ | |
_weightedModel.ModelWithWeight["bbb"] = Tuple.Create(posWeight, negWeight); | |
return this; | |
} | |
public WeightedModelFluentInterface SetcccModel(int posWeight, int negWeight) | |
{ | |
_weightedModel.ModelWithWeight["ccc"] = Tuple.Create(posWeight, negWeight); | |
return this; | |
} | |
public WeightedModelFluentInterface SetdddModel(int posWeight, int negWeight) | |
{ | |
_weightedModel.ModelWithWeight["ddd"] = Tuple.Create(posWeight, negWeight); | |
return this; | |
} | |
public WeightedModel Complete() { | |
return _weightedModel; | |
} | |
} | |
public Dictionary<string, Tuple<int, int>> ModelWithWeight { | |
get { return _modelWithWeight; } | |
set { _modelWithWeight = value; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment