Home
Do you avoid putting business logic into the presentation layer?
  v1.0 Posted at 27/04/2018 8:28 AM by Tiago Araujo
Be sure you are aware of what is business logic and what isn't. Typically, looping code will be placed in the business layer. This ensures that no redundant code is written and other projects can reference this logic as well.

private void btnOK_Click(object sender, EventArgs e)
{
rtbParaText.Clear();
var query =
from p in dc.GetTable()
select p.ParaID;
foreach (var result in query)
{
var query2 =
from t in dc.GetTable()
where t.ParaID == result
select t.ParaText;
rtbParaText.AppendText(query2.First() + "\r\n");
}
}

Bad Example: A UI method mixed with business logics


private void btnOK_Click(object sender, EventArgs e)
{
string paraText = Business.GetParaText();
rtbParaText.Clear();
rtbParaText.Add(paraText);
}

Good Example : Putting business logics into the business project, just call the relevant method when needed​​


Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments:

    Note: Social Media login for Yotpo is not working in IE or Safari, please use Chrome. We are waiting for Yotpo to fix it.