Difference between 3 tiers and n tiers??

Posted by Mesh_2010 under Interview Questions on 3/14/2011 | Points: 10 | Views : 18627 | Status : [Member] | Replies : 11
Hi,

What is Difference between 3 tiers and n tiers Architecture??

Thanks
RameSH sinGH



Responses

Posted by: T.saravanan on: 3/14/2011 [Member] [MVP] Silver | Points: 25
Posted by: Gsolvers on: 3/14/2011 [Member] Starter | Points: 25

Up
0
Down
Simple defintions:

We have tiers of code to make the things more simple and manageable. This is a way to separet the code responsibility and well defined layers. 3 tier layer mainly have a UI, business and data layer. You can implement more than one layer by breaking any of these layer in to more. For e.g. you can break down UI layer into further two layers such as VIEW and controller. You can also break down business layer to make the implementation simple,

Best Regards,

VG
www.TeacherJi.com

Mesh_2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mesh_2010 on: 3/14/2011 [Member] Starter | Points: 25

Up
0
Down

Hello Gsolvers,

ok i understood but

3 tier and n tier both are same are not....


Thanks
RameSH sinGH

Mesh_2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gsolvers on: 3/14/2011 [Member] Starter | Points: 25

Up
0
Down
"n" is a numeric term....it can mean 3 or any more tiers.

Best Regards,

VG
www.TeacherJi.com

Mesh_2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mesh_2010 on: 3/14/2011 [Member] Starter | Points: 25

Up
0
Down

ok thanks
Gsolvers

Thanks
RameSH sinGH

Mesh_2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/15/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Check this link

http://www.coderanch.com/t/153004/java-Architect-SCEA/certification/Difference-between-tiers-tiers

Thanks
Karthik
www.f5Debug.net

Mesh_2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 6/8/2012 [Member] Bronze | Points: 25

Up
0
Down
In 3 tiers includes Business layer,Presentation layer and Data layer
"N" implies any number -- like 2-tier, or 4-tier; basically, any number of distinct tiers used in your architecture


Mesh_2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/19/2012 [Member] Bronze | Points: 25

Up
0
Down
3 Tier architecture have 3 layers

1.Presentation Layer
2.Buisness Layer
3.Data access Layer

//Data Layer

static class DAL
{
const string ConnectionString = "server=.;initial catalog=Employee;user id=sa;password=sa123";

public static int ExecuteNonQuery(string commandText, SqlParameter[] parameters)
{
try
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(commandText, conn))
{
foreach (SqlParameter param in parameters)
cmd.Parameters.Add(param);

int rowsAffected = cmd.ExecuteNonQuery();

return rowsAffected;
}
}
}
catch
{
throw;
}
}

public static SqlDataReader GetReader(string commandText, SqlParameter[] parameters)
{
try
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(commandText, conn))
{
foreach (SqlParameter param in parameters)
cmd.Parameters.Add(param);

SqlDataReader reader = cmd.ExecuteReader();

return reader;
}
}
}
catch
{
throw;
}
}
}

To resemble the table EmployeeDetails I have created the following entity class

class EmployeeEntity
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }

public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("Employee Name = ").Append(this.Name);
sb.Append(" Have Id = ").Append(this.Id);
sb.Append(" Lives In = ").Append(this.Address);

return sb.ToString();
}
}

//Buisness Layer

static class Employee
{
public static int AddEmployee(EmployeeEntity e)
{
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@Id", e.Id);
param[1] = new SqlParameter("@Name", e.Name);
param[2] = new SqlParameter("@Address", e.Address);

return DAL.ExecuteNonQuery("INSERT INTO EmployeeDetails VALUES(@Id, @Name, @Address)", param);
}

public static EmployeeEntity GetEmployee(int id)
{
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@Id", id);

SqlDataReader reader = DAL.GetReader("SELECT * FROM EmployeeDetails WHERE Id = @Id", param);

if (reader.HasRows)
{
EmployeeEntity emp = new EmployeeEntity();
while (reader.Read())
{
int temp = 0;
int.TryParse(reader["Id"].ToString(), out temp);
emp.Id = temp;
emp.Name = reader["Name"].ToString();
emp.Address = reader["Address"].ToString();

break;
}
return emp;

}
else
return null;
}
}


//presentation Layer

class Program
{
static void Main(string[] args)
{
Employee.AddEmployee(new EmployeeEntity() { Id = 1, Name = "Amal", Address = "MyAddress" });
Employee.AddEmployee(new EmployeeEntity() { Id = 2, Name = "Hashim", Address = "Hashim Address" });
Employee.AddEmployee(new EmployeeEntity() { Id = 3, Name = "Rooney", Address = "Manchester" });

EmployeeEntity emp = Employee.GetEmployee(1);

Console.WriteLine(emp);
}
}

Mesh_2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/19/2012 [Member] Bronze | Points: 25

Up
0
Down
Please mark as answer if it helpful to you...That helps others who search the same...

Mesh_2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/20/2012 [Member] Starter | Points: 25

Up
0
Down
3-Tier Architecture have Presentation Layer,BusinessLayer,DataAccess Layer.
N-Tier architecture means we can use number of tiers based on ur architecture.

Thanks & Regards
Hari

Mesh_2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/20/2012 [Member] Starter | Points: 25

Up
0
Down
See this link for 3-tier architecture
http://www.dotnetfunda.com/articles/article71.aspx

see this link for n-tier architecture
http://www.codeproject.com/Articles/434282/A-N-Tier-Architecture-Sample-with-ASP-NET-MVC3-WCF

Thanks & Regards
Hari

Mesh_2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response