Am I setting up my architecture correctly?
-
Im a begining C# programmer and was hoping you guys could help me. Im working on my first real project and I am a little confused on how exactly to set it up. I've read so many articles on this, but they all seem to be saying different things. Here is a psuedo code example of my current setup:
//Data Access Layer class EmployeeDA { public void Insert(Employee emp) { //code to add employee to db } //similar methods for Load, Delete, Update, etc } //Business Logic Layer class Employee { private int id; private string name; private EmployeeDA = new EmployeeDA(); //here would be the code for the properties and constructors public void Insert() { EmployeeDA.Insert(this); } //similar methods for Load, Delete, Update, etc } class Employees : List { public void AddEmployeesToTable() { foreach(Employee emp in this) emp.Insert; } //similar methods for Load, Delete, Update, etc }
Is this correct? I know there are many different ways to do it, so maybe "correct" isnt the right word. I guess what I want to know is if there is a "better" way of doing it. Are there any glaring issues with the way I am doing it currently? Thanks -
Im a begining C# programmer and was hoping you guys could help me. Im working on my first real project and I am a little confused on how exactly to set it up. I've read so many articles on this, but they all seem to be saying different things. Here is a psuedo code example of my current setup:
//Data Access Layer class EmployeeDA { public void Insert(Employee emp) { //code to add employee to db } //similar methods for Load, Delete, Update, etc } //Business Logic Layer class Employee { private int id; private string name; private EmployeeDA = new EmployeeDA(); //here would be the code for the properties and constructors public void Insert() { EmployeeDA.Insert(this); } //similar methods for Load, Delete, Update, etc } class Employees : List { public void AddEmployeesToTable() { foreach(Employee emp in this) emp.Insert; } //similar methods for Load, Delete, Update, etc }
Is this correct? I know there are many different ways to do it, so maybe "correct" isnt the right word. I guess what I want to know is if there is a "better" way of doing it. Are there any glaring issues with the way I am doing it currently? Thanks -
Im a begining C# programmer and was hoping you guys could help me. Im working on my first real project and I am a little confused on how exactly to set it up. I've read so many articles on this, but they all seem to be saying different things. Here is a psuedo code example of my current setup:
//Data Access Layer class EmployeeDA { public void Insert(Employee emp) { //code to add employee to db } //similar methods for Load, Delete, Update, etc } //Business Logic Layer class Employee { private int id; private string name; private EmployeeDA = new EmployeeDA(); //here would be the code for the properties and constructors public void Insert() { EmployeeDA.Insert(this); } //similar methods for Load, Delete, Update, etc } class Employees : List { public void AddEmployeesToTable() { foreach(Employee emp in this) emp.Insert; } //similar methods for Load, Delete, Update, etc }
Is this correct? I know there are many different ways to do it, so maybe "correct" isnt the right word. I guess what I want to know is if there is a "better" way of doing it. Are there any glaring issues with the way I am doing it currently? ThanksHi As you mentioned there is no correct architecture.When you are designing a solution you should consider the domain of the problem that you are solving. There are lots of patterns that you can choose from ( for example Data Access Objects and Active record) If you are working on a small project ( and you don't expect it to become a large application in future) you can mix up the Data Access and the business layer or if you prefer you can have both in your project (It's not very hard to split them afterwards) Be careful not to mix up your user interface layer with your business layer since it's very hard to refactor them afterwards. Take a look at Martin Fowler's articles at his site (www.matinfowler.com) and specially take a look at his Enterprise patterns. Good Luck