fluent interfaces c#
i have doubt smooth interfaces.
we have objects used parameter objects sql interface, here's an example:
using (databasecommand cmd = conn.createcommand(
"select a, b, c tablename where id = :id",
sqlparameter.int32(":id", 1234)))
{
...
}
for parameters, i'd assent specialized options, nonetheless instead adding some-more properties int32 slight (which only many), i guess i'd feeling smooth interfaces.
here's an instance where i've total i am looking into:
sqlparameter.int32(":id", 1234).with(sqlparameteroption
.substitute
.precision(15)
)
i know twin options doesn't clarity form parameter, nonetheless that's doubt about.
in above case, surrogate have stationary ability (or slight i only supplement parenthesis) sqlparameteroption class, since pointing have an instance method.
what i trifle them?
sqlparameter.int32(":id", 1234).with(sqlparameteroption
.precision(15)
.substitute
)
then surrogate have instance ability pointing stationary method. won't accumulate course, i can't have both stationary non-static ability slight same name.
how i this? am i totally wrong lane here?
while re-reading question, i an idea, opposite syntax next some-more sense?
sqlparameter.int32(":id", 1234).with
.precision(15)
.substitute
in box both instance methods whatever returns, specialized category interface sqlparameter options this. i'm certain i'd dump .with part, arrangement methods object, instead only fluent ones.
advice good url's many welcome, i've scoured over examples, nonetheless tend arrangement examples this:
order
.addfreeshipping()
.includeitem(15)
.suppresstax();
(lifted )
edit: followup after responses
from :
class sqlparameteroption
{
open sqlparameteroption precision(int p) {/* ... */; relapse this;}
open sqlparameteroption substitute() {/* ... */; relapse this;}
/* ... */
}
/* ... */
sqlparameter.int32(":id", 1234).with(new sqlparameteroption()
.precision(15)
.substitute());
with approach, have take object, ask parameter. i'm glorious that.
if i used syntax i total an example, this:
sqlparameter.int32(":id", 1234).with
.precision(15)
.substitute());
in case, wouldn't know method ended, any choice have ask the outcome directly.
what preferred? options build adult an outcome vigilant have receptive later, any outcome relates the outcome directly?
my decision:
as says, changes irreversible, potentially theme reversal, building adult state unwell during indicate an difference proceed i'll go.
however, case, i'm going easier proceed modifies sqlparameter vigilant directly.
in case, formula feeling this:
sqlparameter.int32(":id", 1234).with
.precision(15)
.substitute());
edit: gah, that's goes i concentration only thing.
i can't syntax, i'll following, suggested :
sqlparameter.int32(":id", 1234).with(new sqlparameteroption()
.precision(15)
.substitute());
the reason impetus slight takes sqlparameter vigilant an justification amateurish cope vigilant returned with, nonetheless sqlparameter vigilant assembled set adult properly, became proud commanded usage.
Comments
Post a Comment