Back to Basics: OOP and Layered Application Design (Fundamentals to N-Tiered Architecture)

After doing an introduction to basic OOP Principles,

  1. Classes and Objects
  2. Inheritance
  3. Polymorphism (in Taglish)
  4. Encapsulation (also in Taglish, mostly in Filipino)

I am moving the series further to discuss another programming basic which is building an application with its components separated by logical layers. This principle will also serve to be a foundation for writing Tiered Solutions when I get later to the series.

While there have been a lot of enhancements to the .NET Framework since I first wrote about this subject in 2005 or 2006, principle remains the same and I will be writing similarly because previous statistics revealed that those were the most read portions of my blog. There must also have clarity in how that was written so I elected to put the same approach.

To give a brief background, the process of layering is done to group similar program functions into a component for good uses such as flexibility, code readability, and separation of concerns to name a few. Below is an example of a high level diagram of the most common approach.

Where

Presentation Layer provides users with interaction to business functions and processes through its presentation processing logics. Most often in the form of a Web Site Application, Windows Based Applications, and Device Specific Implementations such as ATMs, Tablets, Smart phones, etc.

Business Layer exposes the core functionality of software either by a library or web services exposed to the consuming presentation tier. In practice, program functions are usually encapsulated to a business logic code. It can sometimes contain components that integrate other application components such as a job or a trigger to a Windows Service, depending on your requirements, in other instances; those reside directly from the presentation layer or downstream to the Data Layer.

Data layer provides access to data hosted within the boundaries of the system, a custom data processing logic and data exposed by other networked systems; perhaps accessed through services. The data layer exposes generic interfaces that the components in the business layer can consume.

There are other layers that are considered to be reused across other tiers or on a specific function. Examples are Security, Interfaces, and Helpers some of which we will use the next set of articles.

To kick start the series, let us prep the solution we will be using to get more sense into the diagram I have showed earlier. Open up Visual Studio (or an Express Edition variant such as for Desktop or for Web).

Create a solution with projects (and corresponding project types) listed below. If you have been into the previous articles, we are going to be writing a fictitious Grading system so my students from the previous articles can easily follow.

  1. Grading.Interfaces (Class Library Project)
  2. Grading.Helpers (Class Library Project)
  3. Grading.DataAccess (Class Library Project)
  4. Grading.Business (Class Library Project)
  5. Grading.Services (although a little more advance, but this will showcase another programming principle that is more becoming common especially in the cloud era).
  6. Grading.WebUI (for Web) or Grading.WinUI (for Desktop)

In this set of exercises, we will be using my favorite database management system which is SQL Server (you may use the express variants).

Watch out as we continue this series.

———————————–

Filipino translation:

Para sa pagpapatuloy ng sinimulan kong serye na tumalakay sa ilang importanteng disiplina ng OOP, ang mga susunod na panulat ay tatalakay ng isa pang programming basic kung saan pinapaliwanag ang pagbuo ng isang application gamit ang paghihiwalay ng mga lohikal na mga bahagi. Ang prinsipyo na ito ay magsisilbi rin na pundasyon para sa pagsusulat ng Tiered Solutions sa mga susunod pang mga serye.

Kahit nagkaroon na ng maraming bago sa .NET Framework mula ng una kong naisulat ang tungkol sa paksang ito noong 2005 o 2006, ang mga prinsipyo ay nananatiling pareho. Sang-ayon din sa inilarawan ng istatistika na ang bahagi ng aking blog na may kinalaman dito ang may pinaka-maraming pagbasa kaya pananatilihin ko ang parehas na istilo.

Para magbigay ng maiksing salaysay, ang proseso ng paghihiwahiwalay ng mga bahagi ng programa ay upang makapag-bigay na mas angkop na pag-pangkat ng code upang mas madaling mabasa at makapagbigay ng mas malayang paggamit. Ang larawan sa itaas ay isang halimbawa ng isang mataas na antas ng nagpapakita ng isa sa pinaka-karaniwang diskarte.

(larawan)

Kung saan

Presentation Layer ay nagbibigay ng pakikipag-ugnayan sa mga gumagamit at kung ano ang kayang gawin ng programa sa pamamagitan ng Web Site Application, Windows Based Applications, at Device Specific Implementations katulad ng isang ATM, Tablets, Smart phones, at iba pa.

Business Layer ay naglalantad ng pangunahin at serbisyo na kayang ipamalas ng isang programa na nagbibigay ng karaniwang gamit para sa Web Site o iba pang nasa Presentation Layer. Madalas ay itinatago nito ang mga proseso na hindi kailangang ipakita sa mga taga konsumo nito.

Data layer naman ay nagbibigay ng access sa data o impormasyon na naka-host sa loob ng mga hangganan ng sistema.

May mga iba pang mga layer na itinuturing na reused sa kabuuan ng iba pang mga Tier o sa isang tiyak na function. Mga halimbawa nito ay Security, Interface, at Helpers; ang ilan sa mga ito ay gagamitin sa susunod na hanay ng mga artikulo.

Ang gagamitin nating database management system ay SQL Server.

Read IT, love IT, live IT! J

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s