Dont Be Too Strict About Layering

This is just an idiom, not really a a pattern.

When building a layered architecture like a FourLayerArchitecture, it often does not pay to be TOO strict about enforcing the rule that each layer should talk ONLY to the one directly below it. Often I find that exposing small bits and pieces of lower layers can make your life easier.

For instance, in many cases you might want to manipulate a number of domain objects as a logical unit of work. The place where the objects are logically tied together is in the Application layer of your system. However, in a standard FourLayerArchitecture, persistence is usually handled by an infrastructure layer that is not exposed to the ApplicationModel, since the ApplicationModel should rely mostly on the services provided by the Domain Model.

So, instead of trying to shoehorn transactions into the domain model where they might not belong, expose a tiny bit of the Infrastructure layer to allow transactions to be started at a higher level, in the ApplicationModel layer.

KyleBrown

P.S. Don't assume that the other rule (that layers should not be aware of layers above them) should be relaxed too! That way lies danger...

TS - This is a use of architectural Compression, indicated when performance is not good enough. The trade-off is maintainability. Better to keep full layer independence (via abstraction) and compress only when you can show that performance is a) a problem b) solved by compressing the layers.

I find a problem only arises if you short-circuit the layers. If you Demeter the functionality through the layers, e.g. adding a transaction interface to your domain-layer, then there isn't a problem. It can simply forward the function onwards. Then you keep your point of flexibility and your explicit layering. Transactions are a particular nasty since nested transactions don't often work as well as advertised. Such is life.

I agree that it is often useful for a layer to provide some transaction handling methods as part of its interface, but I do not agree with the title of this page because it implies that it's acceptable to bend the rules and access other layers private parts. It doesn't matter if you access private parts of layers above you or below you, as soon as you do that you have merged the two layers together and lost the benefits of independence that you had. --DavidPeterson


EditText of this page (last edited October 29, 2002) or FindPage with title or text search