Search code examples
c#3-tierpresentation-layermiddle-tierdata-layer

Three tier architecture


I have some questions about three tier architecture.

  1. how to implement an application in three tier architecture correctly?
  2. how to communicate between these tiers ?
  3. Is data tier completely equals to DBMS? (how about in a case if we use stored procedures and how about in a case if we used a object relational mapping framework ?)

looking forward to hear your answers. Thanks.


PS: Please don't understand that I'm asking a general question. ok ? I'm asking how to design a large scale application correctly. What is the BEST way?. Not expecting looooong answers.


Solution

  • These are broad answers, I'll do my best to give you some pointers.

    1. "Correctly" is a somewhat subjective term. Generally speaking, in my opinion the most important thing is to keep the layer in its own module (e.g., its own DLL), and have interfaces going in and out of the module. By using interfaces in each layer, you can separate the definition from the implementation, further decoupling the layers from each other. If there is a single entry point into the layer, and it is based on an interface, you can have several underlying implementations, as needed. In the other direction, if you use interfaces as callbacks, then the layer clients (i.e. the other layers) will only need to implement the interfaces in order to get a good flow between the layers.

    2. That depends on how you implement the layers themselves. If you design the layers like I suggested above, you would simply use interfaces to go into the layer and out of it. Another solution might be to make it asynchronous, using event dispatchers - a layer would simply fire an event, and a different layer would listen to this event and act upon it. It all depends on the specific requirements of the project.

    3. No, the data layer is the layer within the application that interacts with the DBMS. Using ORM is simply a method for implementing the data layer, while using stored procedures is a method for moving some of the logic from the application into the DBMS itself, for a variety of reasons.

    I guess you'll receive several answers; you should take all of them into account, do some reading over the net, and experiment a bit until you find what you like.