Hi Leon,
"N-Tier" is a nice buzz word that seems to get passed around a lot these
days. I would advise you not to think about tiers, but about principles
instead. If you can do so successfully, the tiers will take care of
themselves.
What are the principles? Well, you stated some of them yourself:
I want the application to be easy to
maintenance as well as extend.
That is the chief purpose of all these high-sounding terms that get tossed
around these days, like "MVC" and "N-Tiered." What is it that makes an app
easy to maintain, and easy to extend? Well, organization is the key, and
separation of the various types of functionality is the idea. For example,
you can certainly visualize the difference between a User Interface object,
such as a Web Control, and a Business Logic object, such as a class that
organizes and maintains all functionality for a single user of your app. One
renders HTML in the browser, so that the user can read and interact with it.
Another contains data and functionality for manipulating a set of data.
The key is to keep these "loosely coupled." That is, don't mix them
together. An application, whether it is an executable or a web app, is never
finished, at least until nobody is using it any more. Typically, apps are
launched, and then revised, and re-launched, and revised, etc. etc. etc.
There are several logical divisions of functionality, one of which I have
already mentioned: User Interface vs. Business Logic. A good web app
separates UI from Business logic, so that it is easy to make changes to one
or the other without having to think about the other. The UI is bound to the
business class by some programming interface, which you generally don't want
to change. However, beyond that, you may want to change the way the data
looks when displayed, or you may change the underlying structure of the
data, or enhance functionality without breaking the User Interface.
If you first organize the various logical elements of your app, and keep
them loosely coupled, maintanance and extensibility should be a snap. Of
course, the planning and organization are the most critical parts of the
process. They are the foundation upon which you build. There are many ways
to separate out the various elements. For example, in our web app, we use
custom Server Controls for various functionality. These Server Controls are
built in such a way that they can operate independently of each other. That
way, we can combine, move, and/or revise any of them without affecting the
rest of the app. The Server Controls are all UI, no business Logic. For
that, our Server Controls use Business classes, which handle and manipulate
the data. In addition, we use CSS for layout and positioning. This means
that our developers don't have to think about what the UI will look like to
the user. Our graphic designers create the CSS that handles this.
One final word of advice: Bone up on OOP (Object-Oriented Programming).
Forget about "CodeBehind." A CodeBehind class is just that: a class. It is
much like any other class. It is best to think about classes, not files.
Files exist on the file system. Classes exist in an application. Once the
app is compiled, the files are irrelevant. And thinking in terms of files
only confuses the issue.
Don't use Modules. They are there for backwards compatibility, a kind of
crutch for VB developers who are migrating to OOP and .Net. A Module is
actually compiled to a class, but a static class. However, you can create
any static methods, properties, etc., that you need without ever touching a
Module.And static elements are not as useful as you would think in the .Net
environment. Get used to thinking OOP. It is uncomfortable at first, but
becomes intuitive in a relatively short period of time.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living