MVC Design Patterns: separating model and datasource
Obviously MVC promotes separation of concern开发者_高级运维s. One thing we are struggling with is proper separation of Model from the datasource, with IDs being the main sticking point.
The interfaces that define our model call for an ID of type X
Currently the datasource is SQL server.. but what if it is an xml file for some reason and our ID is of type Y?
Should the ID be an object? Should it be some sort of concrete implementation of an IDataIdentifier interface, which would handle equality?
Assuming the Id is a surrogate, and not a "natural" key for the object, (which of course would have to tailored to and therefore different type for each entity), then if I anticipated needing to change the underlying type of my surrogate key, I would indeed create a custom Type for that Id, which would act as a facade for the underlying type I was getting from external cooperative partners - so that the internal type could be changed later without changing the custom type itself or the many references to it throughout my system...
精彩评论