I really like the 3 + 1 level method. One level for the user interface, one for business logic and for saving data. The last one you say? Domain objects and interfaces. This allows you to load one or two of the main levels plus the domain “level”, and the code should work.
It relies heavily on dependency injection and Inversion of Control principles. The data / persistence layer does only two things. It creates, reads, updates, and deletes data and maps it to the format of a domain object.
The user interface layer does the opposite. It displays and receives data so that the user can relate to it, and displays its output / input in the format of a domain object.
The business logic level needs to know only one thing. Business logic. He does not care about where the data came from, nor does he care about where the data layer is. He knows that he must indicate an account that was simply overloaded, how physically doing this is not part of her job.
The domain objects themselves have no logic; they are just containers for transferring data between levels. This means that you can load domain objects and interfaces without worrying about dependencies.
At the end of the day, I feel like I have a fairly clear code base with clearly separated levels. And with some strict interfaces and good base classes, most of the code just tells the program what to do when X happens. How it should be.
</rant>
Edit: Oh yes. This is true for LINQ, SubSonic , and other ORMs.
Lars mæhlum
source share