Review: S#arp Lite, a Lightweight Framework for Delivering ASP.NET MVC Solutions (Part 2) - the domain
Join the DZone community and get the full member experience.Join For Free
this is a review of the s#arp lite project , the version from nov 4, 2011.
in my previous post, i looked at the general structure, but not much more. in this one, we are going to focus on the domain project.
we start with the actual domain:
i have only few comments about this sort of model:
- this is a pure crud model, which is good, since it is simple and easy to understand, but one does wonder where the actual business logic of the system is. it might be that there isn’t any (we are talking about a sample app, after all).
- the few methods that are there are also about data (in this case, aggregation, and order.gettotal() will trigger a lazy loaded query when called, which might be a surprise to the caller.
- probably the worst point of this object model is that it is highly connected , which encourages people to try to walk the object graphs where they should issue a separate query instead.
next, let us look at the queries. we have seen one example where nhibernate low level api was hidden behind an interface, but that was explicitly called out as rare. so how does this get handled on a regular basis?
hm… i have some issues here with regards to the naming. i don’t like the “find” vs. “query” naming. i would use wherexyz to add a filter and selectxyz to add a transformation. it would read better when writing linq queries, but that is about it for the domain.
one thing that i haven’t touched so far is the entities base class:
and its parent:
i strongly support the notion of comparableobject, this is recommended when you use nhibernate. but what is it about gettypespecificsignatureproperties? what it actually does is select all the properties that has the [domainsignature] attribute. but what would you want something like that?
looking at the code, the customer.firstname and customer.lastname have this attribute, looking at the code, i really can’t understand what went on here. this seems to be selected specifically to create hard to understand and debug bugs.
why do i say that? the comparableobject uses properties marked with [domainsignature] for the gethashcode() calculation. what this means is that if you change the customer name you change its hash code value . this hash code value is used for, among other things, finding the entity in the unit of work, so changing the customer name can cause nhibernate to loose track of it and behave in some really strange ways.
this is also violating one of the core principals of entities :
a thing with distinct and independent existence.
in other words, an entity doesn’t exists because of the particular values that are there for the first and last names. if those change, the customer doesn’t change. it is the same as saying that by changing the shirt i wear, i becomes a completely different person.
domain signature is something that i am completely opposed, not only for the implementation problems, but because it has no meaning when you start to consider what an entity is .
next, we are going to explore tasks.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.