I do a Google search a year later & I find my own post and I don't like it.
There are several issues with this post:
Firstly sending objects over the wire was always a bad idea, this post was trying to dodge that as the team did not want to move to DTOs, which i maintain would have saved us time in the end. The real fix is to map the entities to DTO's and send those over the wire specific to the service calls needs.
Secondly MANY-MANY joins are not cool. There are very few places where Many-Many actually exists. Hiding the join in the Entity should have been done, not eliminating the mapping and the joining classes. Redoing this i would have kept the joining class and mapping as a one-many <-> many-one relationship.
eg to expose a customers favourite restaurants
public class Customer
{
//stuff
public IEnummerable<Restaurant> GetFavouriteRestaurants()
{
foreach(var customerRestaurant in CustomerRestaurants)
{
if(customerRestaurant.IsValid())//some check if required
yield return customerRestaurant.Restaurant;
}
}
This now hides the notion of a CustomerRestaurant entity from the outside world as it can be contained with the realms of the domain entity classes (that being Customer and Restaurant)
Well, i guess its good to review ones work, I'm not happy that this was a decision I made, however acknowledging ones mistake is an opportunity for growth
No comments:
Post a Comment