This question is from a Best Practices point of view.
I am using Micro-ORM to separate DAL with Views. I am often confused on my application design approach. While the Micro-ORM takes care of the separation of layers, I also want separation of business logic.
It is suggested to use Classes in this regard, but use of Classes is puzzling in itself.
For example, I have a Web Form with a Button. On click of this button, I want to call a method called as: AddCompany.
I want to know where should I keep this AddCompany method. If it is residing in the .cs file of the Web Form, the business logic is again tightly coupled.
And if I move this method to a Class, I need to pass all the Web Form input box values as parameters to this class.
I would keep the logic out of the webform.cs because I think that's a 'view' - personally I prefer to collect the information there but don't process it there - pass it on - if possible to a purpose build dll (I assume you are anyway) - so I like to use
an intermediate class, which interfaces with the dll. So, my web forms inherit from this intermediate class and methodds are static so it's kind of like this: -
using MyDAL;
public class IntermediateClass : System.Web.UI.Page
{
public static Result AddCompany(Company company)
{
}
}
//THEN IN WEB FORM
public partial class MyWebForm : IntermediateClass
{
protected void btn_Click(object sender, EventArgs e)
{
//since we inherit
Company c = new Company();
c.ID = (int)hiddenField.Value;
c.Name = txtName.Text;
AddCompany(c);
//resrest.
}
}
This is one method to go about things. Sorry if I barked up the wrong tree.
Regards,
BoogleC
Please mark the right solution as the answer. This helps others find what they're looking for.
Marked as answer by rpk2006 on Jun 25, 2012 07:49 AM
rpk2006
Member
631 Points
629 Posts
Where to put method code which is called on click of a button?
Jun 22, 2012 05:53 PM|LINK
This question is from a Best Practices point of view.
I am using Micro-ORM to separate DAL with Views. I am often confused on my application design approach. While the Micro-ORM takes care of the separation of layers, I also want separation of business logic.
It is suggested to use Classes in this regard, but use of Classes is puzzling in itself.
For example, I have a Web Form with a Button. On click of this button, I want to call a method called as: AddCompany.
I want to know where should I keep this AddCompany method. If it is residing in the .cs file of the Web Form, the business logic is again tightly coupled.
And if I move this method to a Class, I need to pass all the Web Form input box values as parameters to this class.
What is the best way to do this?
BoogleC
Contributor
2208 Points
445 Posts
Re: Where to put method code which is called on click of a button?
Jun 22, 2012 06:40 PM|LINK
Hi,
I would keep the logic out of the webform.cs because I think that's a 'view' - personally I prefer to collect the information there but don't process it there - pass it on - if possible to a purpose build dll (I assume you are anyway) - so I like to use an intermediate class, which interfaces with the dll. So, my web forms inherit from this intermediate class and methodds are static so it's kind of like this: -
using MyDAL; public class IntermediateClass : System.Web.UI.Page { public static Result AddCompany(Company company) { } } //THEN IN WEB FORM public partial class MyWebForm : IntermediateClass { protected void btn_Click(object sender, EventArgs e) { //since we inherit Company c = new Company(); c.ID = (int)hiddenField.Value; c.Name = txtName.Text; AddCompany(c); //resrest. } }This is one method to go about things. Sorry if I barked up the wrong tree.
BoogleC
Please mark the right solution as the answer. This helps others find what they're looking for.