I have to develop a application (Winforms-application) which is connected to a database within a enterprise-intranet.
As I want to keep the application ascalable, maintainable & flexible I a m thinking on which architecture I should use.
In this connection I stumbeled over the N-Tier and MVC Patterns.
As far as I got it the main difference between the two patterns is that MVC has a more triangular structure (Components can communicate with each other), while 3-Tier applications have a straight structure where each component (n) can only forward requests to the component (n+1).
So my idea would be to take the 3-Tier approach. Where the “Presentation Layer, Tier-1” holds the Forms, the “Business Layer, Tier-2” handles the information and logic between Tier-1 and Tier-3 and the “Data Layer, Tier-3” is connected to the database and works with stored procedures.
My question is:
Does this sound like a reasonable desicion to you? Because I read that N-Tier makes sence if you plan on running the single Tiers on different machines, which I do not plan to do.
If you think I chose the wrong approach, what would be a better idea?
Thanks in advance.
MVC and n-tier are two architecture patterns at different levels covering different aspects. They can be used at the same time. It’s not one or the other.
MVC is more a software architecture that can be applied in the presentation tier, one component being Windows Forms. (Whether Windows Forms is fully MVC compatible is a separate discussion.)
N-tier architecture is a system architecture (at a higher level than the MVC architecture). The decision is basically whether you have two tiers (the Windows Forms client as the first tier and the database with the stored procedures as the second tier) or three tiers (the Windows Forms client as the first tier, an application server with the business logic as the second tier, and the database with the third tier as the third tier). Or even shorter: Will the client directly connect to the database or is there an application server in between?
It seems that the use of stored procedures is given. If this is the case, then they probably provide more than just data querying and storage but some business logic as well. In such a case, I tend to go with two tiers.
Other factors that could be relevant are:
Authentication: Is it possible to setup up all users in the database? Or would it be easier to do it on an application server and use a single user to acess the database? Is some sort of single sign on required?
Authorization: Is is possible to check all rights and permissions in the database? If not, then three tiers are required to create a secure application?
Are there any restrictions regarding the network architecture that prohibit to directly access the database?
Do you expect several thousand concurrent users and would like to scale up by setting up several servers?
In general, I tend to go for fewer tiers since it’s easier to implement and costs less (initially and during maintenance). The cost of additional tiers needs to be justified by requirements that depend on the extra tier.