Hi,
I have wrote a 3-tier app for college in .Net 3.5 and I want to use it to show a potential employer as soon as possible. I've realised at the end of it that my decision to do error checking of empty fields and date formats in the UI means that I have put business logic there instead of the BLL. At the moment by BLL is pretty useless as it just takes a DTO from the UI and passes it straight through to the DAL during the appropriate method call, and returns a DTO or List of them in most cases.
I have since read about CSLA.Net which looks good but I don't have time to do a re-write in that particular framework as it looks pretty complex to me. I am looking for the quickest way that results in a good way. I will paste what I have below. Any help very much appreciated!
UI - MainAttractionsView.cs
_________________________
if (ErrorCheckOk(attractionInfo))
{
//some code
HolidayPlanner.BLL.Attraction attractionBLL = new HolidayPlanner.BLL.Attraction();
attractionBLL.AddAttraction(attractionInfo);
}
BLL - Attractions.cs
__________________________
public void AddAttraction(AttractionInfo attractionInfo)
{
SQLServerDAL.Attraction attractionDAL = new SQLServerDAL.Attraction();
attractionDAL.AddAttraction(attractionInfo);
}
DAL - Attraction.cs
__________________________
public void AddAttraction(AttractionInfo attractionInfo)
{
//update DB
}
Note: My AttractionInfo object is just a DTO that has private fields, a constructor and public properties.
Many thanks for any advice.
Simon.
Loading
Simon HarringtonPosted Jul 5, 2010, 2:44 PM
Thanks for the suggestions, they all sound good. I would have been happy to use the idea of throwing exceptions from Attraction.Save() but have since done it. I used the bare bones of business object validation from CSLA.Net. I think it's a good result. In this approach a client updates the BO properties on textchanged, and in response the BO updates a Hashtable of broken rules (a rule for each property). When the broken rule count reaches zero (all rules start broke in the constructor when the fields are empty) an IsValid event is thrown to the client. The client then enables buttons like Save and Update. I guess the BO.Save() could still check for IsValid and throw an exception.
Cheers.
camPosted Jul 3, 2010, 11:33 PM
I understand that you want to move validation logic in ErrorCheckOk(attractionInfo) to BL layer.
You can consider the ideas following:
1. UI will call BLL's AddAttraction() and catch any exception from BLL. AddAttraction will try to save the Attraction object; if it is not valid, throw exception with appropriate message. Based on the exception caught, UI will show an appropriate message to users.
2. To encapsulate validation logic for Attraction objects, you can create a class AttractionInfoValidator. This class has method validate() that returns true/false, and throws an exception on invalid data.
3. (Optional) You can define your own ValidationResults class that will eliminate the need to throw and catch exceptions.