Więc utworzyć biegle interfejs tak:
class FluentTable
{
//as a dumb example I'm using a list
//use whatever structure you need to store your items
List<string> myTables = new List<string>();
public FluentTable addTableCellwithCheckbox(string chk, bool isUnchecked,
bool isWithoutLabel)
{
this.myTables.Add(chk);
//store other properties somewhere
return this;
}
public FluentTable addTableCellwithTextbox(string name, bool isEditable)
{
this.myTables.Add(name);
//store other properties somewhere
return this;
}
public static FluentTable New()
{
return new FluentTable();
}
}
Teraz można go używać tak:
FluentTable tbl = FluentTable
.New()
.addTableCellwithCheckbox("chkIsStudent", true, false)
.addTableCellwithTextbox("tbStudentName", false);
To powinno dać podstawową ideę jak trzeba iść około to. Zobacz fluent interfaces on wikipedia.
Bardziej poprawny sposób to zrobić byłoby wdrożyć biegle interfejs:
interface IFluentTable
{
IFluentTable addTableCellwithCheckbox(string chk, bool isUnchecked,
bool isWithoutLabel)
IFluentTable addTableCellwithTextbox(string name, bool isEditable)
//maybe you could add the static factory method New() here also
}
a następnie wdrożyć go: class FluentTable : IFluentTable {}
wszystkie odpowiedzi były dobre, ale ten naprawdę wykracza poza, Dzięki to było naprawdę pomocne –