Three Tier Architecture: Very Easy to understand, the three tier are:
1. Presentation layer
2. Business Layer
3. Database Layer
Simple Example:
Lets take example of a Songs and Artist.
1. DataAccess Layer
Below is a class of Data Access Layer, that has some dummy/fudge data, we only write DataBase calling method in DataAccessLayer.
It only has object i.e. parameters and Stored Procedure Name that are used to call DB, its a wire between DB and View, it only believes in business.
1. Presentation layer
2. Business Layer
3. Database Layer
Simple Example:
Lets take example of a Songs and Artist.
1. DataAccess Layer
Below is a class of Data Access Layer, that has some dummy/fudge data, we only write DataBase calling method in DataAccessLayer.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DataBaseLayer
{
public class DataAccessLayer
{
string[] ArtistName = { "Akon",
"Shakira", "Michael_Jackson" };
string[] Shakira = { "Waka
Waka", "Addicted to you",
"Beautiful Liar" };
string[] Akon = { "Chammak
Challo", "Lonely", "Dont Matter" };
string[] Michael_Jackson = { "Beat
It", "Dangerous", "Smooth Criminal" };
public string[]
Songs(string ArtistName)
{
string[] ArtistSong = new
string[3];
int i = 0;
if (ArtistName == "Shakira"
)
{
foreach (string
s in Shakira)
{
ArtistSong[i] = s; ;
i++;
}
}
if (ArtistName == "Akon")
{
foreach (string
s in Akon)
{
ArtistSong[i] = s; ;
i++;
}
}
if (ArtistName == "Michael_Jackson")
{
foreach (string
s in Michael_Jackson)
{
ArtistSong[i] = s; ;
i++;
}
}
return ArtistSong;
}
}
}
2. Business Access Layer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataBaseLayer;
namespace BusinessLayer
{
public class BusinessAccessLayer
{
public string[]
DataCalling(string ArtistName)
{
DataAccessLayer dataAccessLayer = new DataAccessLayer();
string [] ArtistSongs =
dataAccessLayer.Songs(ArtistName);
return ArtistSongs;
}
}
}
3. Presentation Layer
It is no where related to database and no link, its only work is to display.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessLayer;
namespace Three_Tier_Architecture
{
class PresentationLayer
{
static int flag = 0;
static string choice
= null;
static void Main(string[] args)
{
while (flag == 0)
{
Console.WriteLine("Please
Enter the Artist Name, Enter Number");
Console.WriteLine("Choose
From: \n 1. Shakira \n 2. Akon \n 3. Michael Jackson");
choice = Console.ReadLine();
flag = CallingBusinessLayer(choice);
Console.WriteLine("Wanna
Continue (Y/N)");
string Reply = Console.ReadLine().ToLower();
if (Reply == "n")
flag = 1;
else
flag = 0;
}
}
public static int CallingBusinessLayer(string
SelectedChoice)
{
BusinessAccessLayer _businessAccessLayer = new BusinessAccessLayer();
string[] Songs = null;
if (flag == 0)
{
switch (choice)
{
case "1":
Songs =
_businessAccessLayer.DataCalling("Shakira");
foreach (string s in Songs)
{
Console.WriteLine("\n
" + s + "\n");
}
break;
case "2":
Songs =
_businessAccessLayer.DataCalling("Akon");
foreach (string s in Songs)
{
Console.WriteLine("\n
" + s + "\n");
}
break;
case "3":
Songs =
_businessAccessLayer.DataCalling("Michael_Jackson");
foreach (string s in Songs)
{
Console.WriteLine("\n
" + s +"\n");
}
break;
}
}
return 0;
}
}
}
A very simple and effective example. no Jargon's used.
things should be pretty clear here.
nice illustration....
ReplyDelete