This is one of those scenarios where "Paralysis by Analysis" seems to have taken hold so advice please!
The project
A fairly simple list of automotive products which include details such as part reference, which vehicles they fit etc.
The front end is an asp.net MVC application.
The backend is SQL, using Subsonic to project the products into domain objects.
Functionality
One of our screens is a product details screen. An ASP.NET MVC Controller calls the product repository to retrieve product details, returns these details (via some automapping to a viewModel) to the view.
Now the killer detail is that we have two or three channels into the web site, depending on the channel, the user needs to see different part numbers.
Lets say for example if it's the Retail channel then the part numbers are as they are in the database, but if the user has come to the site through the Trade channel, the beginning of the part reference is replaced with alternative numbers.
e.g. 0900876 if viewed via the Trade channel becomes 1700876.
Where I'm struggling is in deciding where to encapsulate the "Channel rules" regarding part references (and other details which may alter).
I've considered these alternatives.
Write the logic directly into the domain object
On the Product class we could have a method/property to get the translated part reference.
public string TranslatedPartRef()
{
if (this.Channel == "Trade")
{
return PartRef.Replace("0900", "1700");
}
else
{
return PartRef;
}
}
In this scenario the Product instance must know about the channel, which seems wrong to me.
Encapsulate the logic in another object
We could write a class to handle this part reference translation, or create a Channel class which contains this logic.
What I don't understand though is how to then co-ordinate the two classes.
If the controller calls the repository to retrieve the Product, should it then work out what channel was used and translate the part reference? if so how do I then send the product with it's translated part reference back to the view?
It's also worth noting that this part reference has to show up in search results and other scenarios as well, for that reason I think it needs to be neatly contained within the domain somewhere.