Jump to content

Talk:Fluent interface

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Stimpy77 (talk | contribs) at 09:52, 30 September 2009. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

WikiProject iconComputer science Stub‑class
WikiProject iconThis article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StubThis article has been rated as Stub-class on Wikipedia's content assessment scale.
???This article has not yet received a rating on the project's importance scale.
Things you can help WikiProject Computer science with:

Hello!

1) I tried the c#-Sample, but the compiler alerted 12 Syntax-Errors. Please give a sample with runnable code.

2) The "fluent-interface-benefit" (short intuitive code) is not demonstrated very convincing. I would prefer to see something like:

IConfiguration config = ConfigurationFluent.Create().Color("blue").Height(1).Length(2).Depth(3);

or

IConfiguration config = ConfigurationFluent.CreateColored("blue").Height(1).Length(2).Depth(3);

(Create() or CreateColored() would be static methods, returning a new instance as an "entry-Point" into the fluent interface.

That is no really good Sample too, because c#2008 provides the with-Keyword, so one could instantiate without fluent interface as well:

var config = new Configuration() with { Color = "blue", Height = 1, Length = 2, Depth = 3 };

3) A better sample would result in stuff like:

// List<SpecialItem> _SpecialItems = new List<SpecialItem>();
SpecialItem.CreateColored("blue").Height(1).Length(2).Depth(3).AddTo(_SpecialItems);

That would demonstrate, how fluent interface reduce nesting. Compare to:

// List<SpecialItem> _SpecialItems = new List<SpecialItem>();
_SpecialItems.Add(new SpecialItem() with { Color = "blue", Height = 1, Length = 2, Depth = 3 });

Unfortunately the benefit "help from Intellisense" (a fluent interface supports fluent writing code) cannot be shown in an article, or would you like to add screenshots?

ErfinderDesRades (talk) 11:11, 15 December 2008 (UTC)[reply]


IMO the published sample is garbage. Chaining in itself does not make for readability and the ALT.NET community is severely abusing mere chaining with this misunderstanding. There's nothing less readable about

myObject.SetValueX(1);
myObject.SetValueY(2);

than

myObject.SetValueX(1).SetValueY(2);

In my opinion, this actually makes it less readable because these are distinct statements that are being slurred together.

I agree that the samples from ErfinderDesRades are better. Jon (talk) 09:52, 30 September 2009 (UTC)[reply]