<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Haugerns Development Escapades &#187; fluent interface</title>
	<atom:link href="http://www.haugern.net/blog/category/fluent-interface/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.haugern.net/blog</link>
	<description>Morten Haug on development and other curiosities</description>
	<lastBuildDate>Sun, 31 May 2009 21:56:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>My first Fluent Interface experience</title>
		<link>http://www.haugern.net/blog/my-first-fluent-interface-experience/</link>
		<comments>http://www.haugern.net/blog/my-first-fluent-interface-experience/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 20:44:30 +0000</pubDate>
		<dc:creator>haugern</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[fluent interface]]></category>

		<guid isPermaLink="false">http://www.haugern.net/blog/my-first-fluent-interface-experience/</guid>
		<description><![CDATA[The starting point
A pretty standard API involves a factory and an add-method. In between the New/Create method call, we usually set some properties on the created child object. When we&#8217;re done, we add it to the collection of its parent/container. The factory and the parent/container are often collocated. Below is the standard API I had [...]]]></description>
			<content:encoded><![CDATA[<h3>The starting point</h3>
<p>A pretty standard API involves a factory and an add-method. In between the New/Create method call, we usually set some properties on the created child object. When we&#8217;re done, we add it to the collection of its parent/container. The factory and the parent/container are often collocated. Below is the standard API I had as a starting point.</p>
<pre class="code"><span style="color: rgb(43,145,175)">IRibbonItem</span> button = m_view.RibbonMenu.CreateButton();
button.Name = <span style="color: rgb(163,21,21)">"Save"</span>;
button.Image = GetImage(<span style="color: rgb(163,21,21)">"save.jpg"</span>);
m_view.RibbonMenu.AddItemLink(button);

<span style="color: rgb(43,145,175)">IRibbonPage</span> structurePage = m_view.RibbonMenu.CreateRibbonPage();
structurePage.Name = <span style="color: rgb(163,21,21)">"Standard"</span>;
m_view.RibbonMenu.AddPage(structurePage);

<span style="color: rgb(43,145,175)">IRibbonGroup</span> bsGroup = structurePage.CreateGroup();
bsGroup.Name = <span style="color: rgb(163,21,21)">"BS"</span>;
structurePage.AddGroup(bsGroup);

<span style="color: rgb(43,145,175)">IRibbonItemGroup</span> moveButtons = m_view.RibbonMenu.CreateButtonGroup();
bsGroup.AddItemLink(moveButtons);

<span style="color: rgb(43,145,175)">IRibbonItem</span> outButton = m_view.RibbonMenu.CreateButton();
outButton.Image = GetImage(<span style="color: rgb(163,21,21)">"out.jpg"</span>);
outButton.Name = <span style="color: rgb(163,21,21)">"Out"</span>;
moveButtons.AddItemLink(outButton);

<span style="color: rgb(43,145,175)">IRibbonItem</span> inButton = m_view.RibbonMenu.CreateButton();
inButton.Image = GetImage(<span style="color: rgb(163,21,21)">"in.jpg"</span>);
inButton.Name = <span style="color: rgb(163,21,21)">"In"</span>;
moveButtons.AddItemLink(inButton);
</pre>
<p><a href="http://11011.net/software/vspaste"></a>&nbsp;</p>
<p>Look at the above code and then tell me you haven&#8217;t done it before. Bleh&#8230; In the above code I&#8217;m setting up a ribbon menu structure (as found in various Office 2007 products). The code is tedious to write, and there&#8217;s a lot of it. So what if I tried to wrap the API so I could set up my ribbon menu more elegantly, and how do I do that?</p>
<h3>The result</h3>
<p>I&#8217;m going straight to the point and I&#8217;ll show you the resulting code. (Because I&#8217;m really pleased with it and must share it!) One thing I additionally might do is to resolve the image implicitly from the name inside the configurator to make the footprint even smaller. Oh, and please don&#8217;t get hung up on the literals. I&#8217;m trying to get a concept across here, give me a break!</p>
<pre class="code"><span style="color: rgb(43,145,175)">RibbonConfigurator</span>.Configure(m_view.RibbonMenu).With.
    Toolbar.With.
        Button(<span style="color: rgb(163,21,21)">"Save"</span>, GetImage(<span style="color: rgb(163,21,21)">"save.jpg"</span>));

<span style="color: rgb(43,145,175)">RibbonConfigurator</span>.Configure(m_view.RibbonMenu).With.
    Page(<span style="color: rgb(163,21,21)">"Standard"</span>).With.
        Group(<span style="color: rgb(163,21,21)">"BS"</span>).With.
            ButtonGroup().With.
                Button(<span style="color: rgb(163,21,21)">"Out"</span>, GetImage(<span style="color: rgb(163,21,21)">"out.jpg"</span>)).And.
                Button(<span style="color: rgb(163,21,21)">"In"</span>, GetImage(<span style="color: rgb(163,21,21)">"in.jpg"</span>));
</pre>
<p>&nbsp;</p>
<h3>Next time</h3>
<p>Some other time I&#8217;ll talk some more about Fluent Interfaces, and the makings of my RibbonConfigurator.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haugern.net/blog/my-first-fluent-interface-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
