Recommendations to enhance Fluent Interface

May 20, 2011 at 2:19 PM

Current:

var result = RequestSubmitter.GetInstance()
                .WithUrl("http://www.bbc.co.uk/search/news/")
                .Item.WithNameIs("q").ValueIs("Queen Elizabeth II")
                .ConnectWith.Item.WithNameIs("video").ValueIs("on")
                .ConnectWith.Item.WithNameIs("audio").ValueIs("on")
                .ConnectWith.Item.WithNameIs("text").ValueIs("on")
                .WithRequestTypeIs(RequestMethodType.Post)
                .BuildUrl()
                .GetDataFromUrl();

 

Proposed:

var result = FluentRequest.ForUrl("http://www.bbc.co.uk/search/news/")
                .With(RequestMethodType.Post)
                .Parameter("q").Value("Queen Elizabeth II")
                .Parameter("video").Value("on")
                .Parameter("audio").Value("on")
                .Parameter("text").Value("on")
                .BuildUrl()
                .GetDataFromUrl();

I would like to say good work with your project and that I agree the WebRequest class usage is completely hokey. I would recommend adopting a FluentInterface DSL that is more inlines with my proposed usage. Fluent Interfaces are best when you can read them as plain text english with minimal stumbling and repetition. Read both of these DSLs outloud to yourself and I think you'll agree with my proposed changes.

Dec 21, 2011 at 8:25 PM

the project is dead or continues ?