This is one of those scenarios where Analysis Paralysis seems to have strengthened, so advice please!
Project
A fairly simple list of automotive products that include details such as a link to parts, which vehicles they fit, etc.
The front end is an asp.net MVC application.
The backend is SQL, using Subsonic to design products in domain objects.
Functionality
One of our screens is the product details screen. The ASP.NET MVC controller calls the product repository to obtain product information, returns this data (after some automatic conversion to viewModel) to the view.
Now the killerโs detail is that we have two or three channels on the website, depending on the channel, the user needs to see different part numbers.
Suppose, for example, if it is a retail channel, then the part numbers are as they are in the database, but if the user came to the site through the trading channel, the beginning of the circulation of the part is replaced by alternative numbers.
eg. 0900876, if you look through the trading channel, it becomes 1700876.
Where I am afraid, I have to decide where to encapsulate the Channel Rules for references to details (and other details that may change).
I reviewed these alternatives.
Writing logic directly to a domain object
In the Product class, we could get a method / property to get a link to the translated part.
public string TranslatedPartRef() { if (this.Channel == "Trade") { return PartRef.Replace("0900", "1700"); } else { return PartRef; } }
In this case, the product instance should know about the channel, which seems wrong to me.
Encapsulate logic in another object
We could write a class to handle this translation of a link to a part, or create a Channel class that contains this logic.
What I do not understand is how to coordinate these two classes then.
If the controller calls the repository to retrieve the Product, should it then determine which channel was used and translate the link to the details? if so, how can I then send the product with it, translating part of the link back to the view?
In addition, it is worth noting that this part of the link should appear in search results and other scripts, and also, for this reason, I think it should be neatly contained in an area somewhere.