4

I've worked on a project that implements a three-tier architecture with the following design:

  1. Presentation Layer - Uses PHP with an MVC framework to handle frontend presentation and business logic. This layer makes calls to the service layer, which accesses the data.
  2. Data Access Layer - Uses C# .NET and is separated into Service, Business Logic, and Data Layer. Called by the Presentation Layer. Makes calls to the database and serializes responses to return to the Presentation Layer.
  3. Data Layer - The database. Provides all of the data for the above two layers.

I understand that a three-tier approach can help security, since there is still no access to the data if the Presentation Layer is compromised. Although this is true, it seems like this approach is over-complicating it a bit, especially since I'm forced to write two models for the same object in the first two layers.

So my question: Is this a bad implementation of a three-tier architecture? If so, how could it be improved? What are the drawbacks, if any, of simply having an MVC implementation that has access to the database? What approache(s) do you use for your web applications?

Thanks for the help!

user543936
  • 407
  • 1
  • 4
  • 13
  • 3
    There are major differences in n-tier and MVC architectures. Do not mix the two. – Andrew Sledge Dec 16 '10 at 14:42
  • The top tier is web browser, a thin client. IMO what you are have is n-tier and not 3-tier. Of course 3-tier can be seen as subset of n-tier. – sanjeev Jan 09 '12 at 10:37

4 Answers4

3

It looks to me like your 3 tiers are the same as View, Controller Model. If your php is mainly making calls to your #2 layer, then I would think itself doesn't need to be MVC unless you have a very complicated presentation layer that itself should be organized into MVC, for instance if you have complicated navigation or user authentication logic.

Matt
  • 3,778
  • 2
  • 28
  • 32
0

There is nothing necessary in programming. But there are a bunch of practices, that were prooven by years as something-you-can-follow-to-get-better-results. N-tier separation is just one of that practices.

http://en.wikipedia.org/wiki/Multitier_architecture

Your description follows the description in the wiki, so - it is suitable way to implement 3-tier app.

But remember, you don't ought to do anything - just follow the way it is comfortable for you. And in future you'll have your own set of practices that work for you specifically.

zerkms
  • 249,484
  • 69
  • 436
  • 539
0

I think your complication stems from the fact that you're using PHP and .NET, which aren't directly compatible. If you eliminated one of those (only used PHP or only used .NET) that would simplify things. Otherwise, I think you're using a good approach.

Bernard
  • 7,908
  • 2
  • 36
  • 33
0

The value of the approach is not just for security, it also facilitates maintainability.

I am not sure I understand the concern: "especially since I'm forced to write two models for the same object in the first two layers." This would seem to be because you are using two different programming languages for the UI and the back-end. I'm guessing C# "data access layer" contains a complete object model which you then have to replicate in your front end.

The problem seems to be that you have two middle tiers that mirror each other, because you're using two languages, not that you are using a n-tier architecture

Jamie Treworgy
  • 23,934
  • 8
  • 76
  • 119
  • 1
    Precisely. In my mind, I would think that by implementing each layer with the same language, you could add a shared layer where models are accessible from both. – user543936 Dec 16 '10 at 14:59
  • Well, by implementing each layer in the same language they could talk to each other directly. What you are doing is the equivalent of two people speaking through a translator. It can be done, but it's a lot more work, and it's inevitable that there will be miscommunications. I can't imagine why anyone would voluntarily design an application this way, debugging must be a nightmare. – Jamie Treworgy Dec 16 '10 at 15:04
  • Right now, the majority of the logic lies in the PHP layer, which simply makes calls to the .NET Layer with parameters. So, the .NET layer is basically only acting as a database connection and query builder. – user543936 Dec 16 '10 at 15:15