Skip to content

Instantly share code, notes, and snippets.

@neo125874
Created August 18, 2016 02:53
Show Gist options
  • Save neo125874/fb23fc89435c43392fdeb2112aeea754 to your computer and use it in GitHub Desktop.
Save neo125874/fb23fc89435c43392fdeb2112aeea754 to your computer and use it in GitHub Desktop.
fluent interface implementation example
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