Multitier

From Pin Eight
Jump to: navigation, search

This is a mini-rant, a short essay refuting a common misconception among users of an Internet forum. If you think this essay is FUD, feel free to explain why on the essay's talk page.

"Tires don exits."
-- Tier denier on Smash World Forums
"Tiers are for queers!"
-- SomaRuiz, tier denier

A multitier application is a computer program or system composed of several layers, with each layer interacting only with those layers adjacent to it. For example, an application built on the model-view-controller paradigm has a "model" layer that interacts with the data, below a "view" layer that interacts with the user. A three-tier application has a "presentation" layer equivalent to a view, on top of a model split into an "logic" layer and a "data" layer. A program can be ported to another platform by writing a new view and keeping the vast majority of the model, as long as both platforms support the same programming language.

Different layers may run as different threads in a single process, such as an activity or service in Android.[1] They may even run in different processes on different machines, such as the client and server of an online video game, the logic and presentation of a web application, or the logic and database of a large web application.

A layer might be implemented redundantly, with one layer requesting that an action be performed and another layer checking its work. This double-checking is common in web application logic: the JavaScript program running on the client machine needs to quickly check user actions for validity to remain responsive, while the back-end running on the server needs to check the same actions for validity before they are committed.

This pattern is useful for video games: the graphics and sound fit in the view, while the game physics fit in the model. Ordinarily, the main loop of a video game looks like this:

  1. Read user input
  2. Run the game model to advance it by one time quantum (16.7 ms). This handles physics and other object behaviors.
  3. Render video
  4. Play sounds
  5. If game not over go to 1

Ideally, step 2 (the game model) need not change from one platform to another.

As long as two platform share a programming language, an application can be ported from one to the other by writing a new view. An application might be developed for, say, Android and iOS, with a view that meets each platform's "human interface guidelines" for how an interactive view should behave. Or a video game may be ported to multiple game consoles with machine-specific parts of the graphics engine rewritten for each platform.

However, there are still plenty of popular platforms that do not share a language in which to implement a shared model. For example, how would one share a component between an application for Windows Phone 7 and Xbox 360, which runs only C# and other managed languages that compile to verifiably type-safe CIL and do not use the DLR, and the corresponding component for iOS, which runs Objective-C++? Some people, especially fans of Apple products, think this incompatibility is a good thing. They even propose barriers to cross-platform operation, such as different programming languages, ostensibly to discourage sharing parts of the view among platforms. Case in point: Apple's strong preference for Objective-C over Java, C#, or ActionScript.[2] It appears requiring a particular programming language appears to be motivated less by human interface guidelines than by a device manufacturer's desire for killer applications that are exclusive to its platform.

Two platforms that do not share a common language can share logic in one of two ways, neither of which is ideal. One is to have a developer rewrite the program line-by-line by hand in the other platform's language. This introduces errors, and making changes to multiple versions in parallel would violate the principle of not repeating yourself. The other way is to implement a scripting language in which the entire logic layer is written, which can prove very inefficient in time and battery power. Xamarin's answer is to let the Windows Phone 7 port dictate the choice of implementation language for all platforms. This way, components shared with an application for WP7 run in Xamarin's CLR reimplementation for Android and iOS, which a large company like Zynga or Facebook can afford but many individual developers cannot.

Personal tools