Fervent Coder

Coding Towards Utopia...by Rob Reynolds
posts - 278 , comments - 431 , trackbacks - 0

My Links


Rob Reynolds

Subscribe to Fervent Coder RSS
Subscribe to Fervent Coder by Email

About Me

I manage several open source projects. Need...
   ...package management for Windows?
   ...automated builds?
   ...database change management (migrations)?
   ...your application to check email?
   ...a monitoring utility?

I also write for

Like what you are reading? Want to buy me a cup of coffee?
PayPal - The safer, easier way to pay online!


Post Categories


Nothin but .NET Developer Boot Camp - Day 4

So you may notice this post is a little late.  The course moved to an open format today and the last people left for the night at 4:30 AM. That's 9 AM to 4:30 AM.

Basically today we got direction from JP and then formed groups that we worked with all day to implement an end to end solution from the point that we were already at.  One of the things you will push yourself for today is understanding fluent interfaces to whatever extent that you can. The other part is how to build them.  They are much harder to build and grokk than a normal interface.

Fluent Interfaces

We have been working with fluent interfaces all week and JP has kept pushing us to find new ways to build them.  Basically a fluent interface is one that reads almost like a sentence when making calls to the code (almost as if discoverable).

So let's talk about the old way first.  Imagine building an interface with a method Add() on it.  So you would call something like routes = new Routes(); and then routes.Add(something); right?

Routes routes = new Routes()


return routes;

Now try to imagine that as a fluent interface.  You could call something to the effect of:


So what do you suppose it is that makes it fluent?  It reads like a sentence. Route to something when route contains certain path "certain path".  It makes it very easy for consumers and clients of this code and even users to understand the intent of the code. It reads like a sentence.

So let's take a look at two things I wrote today (in addition to other things :D). Both use Static Gateway.

foreach (var product in Repository.get().a_list_of<Product>(with_parameters))
    yield return Map.from(product).to(a_product_browser_dto());

What you notice here is again, it reads like a sentence. "Repository get a list of product with parameters." "Map from product to a product browser dto."

Map and Repository are gateways. This is what Map looks like.

public class Map { public static MapBuilder<From> from<From>(From from_object) { return new MapBuilder<From>(from_object); } } public class MapBuilder<From> { private readonly From from_object; public MapBuilder(From from_object) { this.from_object = from_object; } public To to<To>(To to_object) { return Container.get_me_an_implementation_of_an<IMapper<From, To>>().map_from(from_object); } }


public interface IMapper<From, To>
    To map_from(From from_object);

Behind the scenes it actually uses the same IMapper that we have been using for awhile. The fluent interface is quite awesome, but it can be an advanced topic.

So day 4 was long, but the time FLEW by so you don't really notice how much time has gone by. This whole week seems to fly by because you are having so much fun and learning so much!

Print | posted on Friday, November 21, 2008 4:49 AM | Filed Under [ Code Personal ]


Comments are closed.
Comments have been closed on this topic.

Powered by: