About Me

Training

Nothin But .Net Developer Bootcamp

Navigation

Search

Categories

On this page

Archive

Blogroll

 Agile Developer Venkat's Blog
 Ayende @ Blog
 B#
 Barry Gervin's Software Architecture Perspectives
 Boy Meets World
 Brad Abrams
 Canadian Developers
 Christopher Steen
 Claritude Software News
 Clemens Vasters: Enterprise Development and Alien Abductions
 Coding Horror
 Coding in an Igloo
 Dare Obasanjo aka Carnage4Life
 Darrell Norton's Blog [MVP]
 David Hayden [MVP C#]
 Don Box's Spoutlet
 Eric Gunnerson's C# Compendium
 EZWeb guy: Jeffrey Palermo [C# MVP]
 Fear and Loathing
 Generalities & Details: Adventures in the High-tech Underbelly
 Greg Young [MVP]
 Greg's Cool [Insert Clever Name] of the Day
 IanG on Tap
 Ingo Rammer's Weblog
 ISerializable - Roy Osherove's Blog
 James Kovacs' Weblog
 Jason Haley
 Jean-Luc David
 Jeremy D. Miller -- The Shade Tree Developer
 JetBrains .NET Tools Blog
 Jimmy Nilsson's weblog
 John Bristowe's Weblog
 John Papa [MVP C#]
 Jon Skeet's Coding Blog
 JonGalloway.ToString()
 Jump the Fence or Walk Around
 Lambda the Ultimate - Programming Languages Weblog
 Larkware News
 Lutz Roeder
 Marquee de Sells: Chris's insight outlet
 Martin Fowler's Bliki
 Mike Nichols - SonOfNun Technology
 MSDN Magazine - .NET Matters
 MSDN Magazine - All Articles
 OdeToCode Blogs
 Onion Blog
 Planet TW
 Raymond Lewallen [MVP]
 Rockford Lhotka
 RodMan's Corner
 Roger Johansson's blog
 Sahil Malik - blah.winsmarts.com
 Sam Gentile's Blog
 Scott Bellware [MVP]
 Scott Hanselman's Computer Zen
 ScottGu's Blog
 secretGeek
 Service Station, by Aaron Skonnard
 Signum sine tinnitu--by Guy Kawasaki
 Stephen Toub
 Steve Eichert's Blog
 Steven Rockarts
 The Blog Ride
 The Coding Hillbilly
 The Daily WTF
 TheServerSide.net: News
 Tim Gifford
 Vance Morrison's Weblog
 you've been HAACKED

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 385
This Year: 110
This Month: 0
This Week: 0
Comments: 973

 Thursday, September 27, 2007
Thursday, September 27, 2007 9:33:52 AM (Mountain Standard Time, UTC-07:00) ( Programming )

Currently, in a lot of the projects that I work on I tend to take a top down approach to development. Which means that I will start at test that focus on the presentation layer of the application.

Some people are curious as to this approach. My answer for this is simple. From the customers perspective, the first and simplest entry point to the application is the UI of the application itself. The UI also happens to be the place where developers spend a lot of their time, as that is often the place of most contention because of user expectations for how the UI should behave. By focusing on presenters and their accompanying view implementations, I can focus on stubbing out the behavior of the required service layer pieces as well as the accompanying Screen Bound DTOS that are required to present data to the particular user interface.

The concept of Screen Bound DTOS is probably not a new one, but one that I have been able to use with lots of success. Most people who look at my code are probably aware that I favour the use of DTOS with regards to use in the presenter to service layer communication as well as for displaying data in the UI. This is because you can build DTOS specific to the screens that they are going to service. They are completely separate from the underlying domain layer that will ultimately handle the business logic, and therefore are completely unaffected when a change to the domain model actually occurs. When a domain object or set of domain objects that ultimately map to a DTO change, the only thing that needs to change is the mapping from domain to the DTO. This ultimately allows my domain to evolve completely independently of the needs of the user interface.

Also keep in mind that a given screen may have the concept of more than one type of DTO for the different behaviours that can occur. For example, when I am displaying a list of products to purchase in an online store, I may have the need for a DTO that consists of the name, description, and price, as well as the SKU number for the product. When it comes time to add an item to my cart, what are the pieces of information that are really relevant to pass to the service layer? Only the SKU and the number that I want to add. I can encapsulate this information in an AddItemToCartDTO that contains the sku of the product and the quantity to be added. This DTO is free of all of the extra noise that existed in the previous DTO that is not necessary for the add to cart behavior

With regards to the presenter to service layer communication, these DTOs become essentially stripped down commands without the behaviour necessary to complete the task.

Using this technique and Top Down Development, I can completely finish off a screen, hand it off to the user to verify that it works the way that they want. I can do this by stubbing out service layer implementations to return fake data.

Once I get sign off from the user that the screen is up to par, I can now switch down to another layer and repeat the process of Top Down Development, from a different layer in the application.

 

Thursday, September 27, 2007 11:15:46 AM (Mountain Standard Time, UTC-07:00)
Hi JP! I guess two issues nagged me when i approached things like this before. First, deep object graphs bogged me down...perhaps that was because i was trying to do too much with my dto?
Second, I found too much mirroring of my domain model in the ui so questioned the wisdom of maintaining the dto's. I realize a domain gets richer thru lots of refactoring and eventually the mirroring is lost, but doesn't it seem like your jumping the gun by starting out with DTOs?
MIKE
Thursday, September 27, 2007 11:30:35 AM (Mountain Standard Time, UTC-07:00)
Isn't that was is commonly known as Application/Presentation model.

I personnally don't like the term DTO since most of the time, some sort of logic will be included in the model.

e.g.
- IBindingList implementation
- Derived properties: class Model { public Color Color { get { return domainObject.Amount > 0 ? Colors.Black : Colors.Red; } } }
- Resources lookup
Francois Tanguay
Thursday, September 27, 2007 12:45:47 PM (Mountain Standard Time, UTC-07:00)
This is something that I've been looking at doing lately, (my current project can domain object mirrored DTOs and I am seeing some pain with this approach.

One of the things I have in my domain object is some logic for making its use a lot easier and encapsulating common operations for example. (The object is a Timecard and has lots of TimeSpan and date calculation logic inside of it.

If I go the DTO route I lose all of this from the consuming code (the presenter).

I ended up just hydrating another domain object from the DTO so that I can access all this stuff, but then use the DTOP for transfer over the wire (may have remote services, may have in proc ones).

Can you write some more posts on using this approach in detail?
Thursday, September 27, 2007 3:55:03 PM (Mountain Standard Time, UTC-07:00)
I've recently started using what I was calling Presentation Models alongside my MVP architecture in order to simplify (even further) the view implementation.
I must admit I haven't read martin fowlers write up on 'Presentation Model' recently, so I'm probably misusing the term, but whatever - its certainly simplified my
views!
Thursday, September 27, 2007 5:09:53 PM (Mountain Standard Time, UTC-07:00)
I try to do this where possible. A couple of times I get some push back, as the perception is that you're doing work twice: once to pull stuff from the database, and then a second time to transform it into a presentation DTO. Regardless, I think the effort is worth it.
Saturday, September 29, 2007 12:17:37 PM (Mountain Standard Time, UTC-07:00)
"I try to do this where possible. A couple of times I get some push back, as the perception is that you're doing work twice: once to pull stuff from the database, and then a second time to transform it into a presentation DTO. Regardless, I think the effort is worth it."

Sorry, but reading the article and all the coments i did not get what is the magic thing you get from transforming your objects to presentation DTO?

I see no value in creating it, since the presentation is used only in one specific place, it does not abstract anything, nor does it allow you to encapsulate logic or data and use it in some other place, except for displaying data in that very same window.

Maybe i miss the context here or specific business needs to accomplish? Otherwise, i see that this area is abit overengineered for the sake of engineering.
Thursday, October 18, 2007 3:42:52 PM (Mountain Standard Time, UTC-07:00)
It just occurred to me the other day that if I define a DTO interface (e.g., ICustomerDTO) for part (or all) of the properties on a web form (e.g. Customer.aspx.cs), the view interface that the web form implements (e.g., IViewCustomer) may as well also implement the DTO interface (e.g., public interface IViewCustomer:ICustomerDTO{ }). Am I off my tree here?
Jason
Tuesday, February 12, 2008 12:35:02 AM (Mountain Standard Time, UTC-07:00)
Nice post Jean-Paul.

Something feels good about this approach - I think it's the de-coupling. Views become simple receivers and senders of "dumb" messages (the DTOs), essentially having their own "user model". They can then be evolved and tested without concern for the shape of the domain model. There is something elegant about that.

Jean-Paul, how do you do your DTO-Entity mappings? I'm worried about violating the DRY principle and repeating myself everywhere. What if the GUI model and domain model overlap 90% on a particular view, would you still use DTOs?

My hunch is that you could do what Ruby on Rails does: use a Hash as your DTO, and then make sure that hash keys are named to a convention so they can be mapped to the domain model automatically.

myDto["customer.Forename"] = "Tobin"; //use clever reflection to map this back to Forename on entity

Of course, if you use a convention, you probably need to know your entity structure before you start. Drat!!!


Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):