views:

333

answers:

3

Recently I have been debating on the best way to handle communication up the chain in n-tier architecture.

Currently the methods I am doing is throwing and handling exceptions between layers for errors, and using events/delegates for other communication (to update progress bars and such). Are these the best way or is there another method that I have overlooked that would be considered better practice?

+1  A: 

I would say you are on the right track as far the exception handling is done - that is the Chain of Responsibility pattern implementation. It is always good to throw the exception up the chain. As for the other one (events/delegates) I didnt quite understand your statement so couldnt comment on that.

OpenSource
+1  A: 

Exceptions are indeed a good way to handle errors from lower tiers.

In my mind, delegates are most useful when one object that owns another object needs to customize that object. That could make sense if your tiers logically "own" the objects on lower tiers—otherwise, I'd probably shy away from the delegate pattern and use events.

John Calsbeek
A: 

I have tried to use the Adapter pattern. The main objects lie in the logic layer and are wrapped, using composite objects so that the presentation and data access layers may work. Most of the presentation and data access layer classes use interfaces. The wrapper (composite) objects lie in the presentation and data access layers and implement the interfaces of those layers.

In addition to composite objects, there are controller objects which may pull data from the logic objects and create new objects (ie a list of strings).

Scott Izu