I design simple DAL using Generic, i have 2 business objects matched to each other, one in BusLayer and the other in DAL.
DAL just deal with DAL.Domain.Categories
BusLayer see Business.BusinessObject.Categorie and DAL.Domain.Categories
DALProxy is a class in business layer and it the only class talk with DAL
in Business Layer when developer need to get a recored from DB , he will write the following:
public
Business.BusinessObject.Categorie GetCategorie(string primKey){
DALProxy proxy = new DALProxy("Connection string ....");Business.BusinessObject.Categorie cat = proxy.GetRecord
Return cat;
}
Then GetRecord Method in DALProxy call DAL DAO
public
T GetRecord{
DAO dao = new DAO("");T busObject = new T(); U domainObject = dao.GetRecord(key);
// then map U to T before return T
T busObject = Mapper.Map(domainObject ,busObject );
return busObject ;
}
My Question is how to make Proxy.get Record take just T, not T and U.
i mean developer not need to know the matching Domain object and type it.
i need it to be implicit, and to be my problem is explained well i have a stupid solution:
in proxy getrecord i will check type of T, if it a type of Categories then Call DAO.getRecord
any smart solution
Ahmed SolimanPosted Apr 21, 2008, 11:27 AM
1-business
2-DAL
3-presentation
4-domain (business objects)
refererance rule as following:
presentation -> business
presentation -> Domain
presentation -> DAL
business -> DAL
business -> Domain
Domain -> DAl
So it seems bad design, presentation layer should see just Business layer which have business objects in the same layer. but since my business object is somehow complex and have logic and attriputes related to Dal, i said developer not need to see all of these information, he should see simple business object with getter and setter. Also in future if we need to create custom mapping between domain object and business object for ex( compine two domain object in one busobject or map column first name and last name to Full name column).
so i suggested to be domain object in DAL and busobject in Business Layer.
i found a solution to my problem, i don't know it will fit in all cases or not:
public abstract class BaseBusiness
{
public void GetRecord(object key)
{
DAO dao = new DAO("");
Y domainObject = dao.GetRecord
ObjectMapper.Map(domainObject, this);
}
}
public class Categories : BaseBusiness
{
// constructor
public Categories(object key)
{
GetRecord(key);
}
}
if you see my design is not good , give me your sugessions
thanks at all
Matthew CochranPosted Apr 21, 2008, 10:32 AM
The problem is that you have no place storing the relationship between the 'T' and 'U' types so you have to specify both. You could create a dictionary of mappings and keep it around (Dictionary) but I think your solution will become very complex and hard to maintain.
Can you refactor to totally encapsulate the DAO and all the DAO objects inside your business layer? People consuming your library should not have to deal with the DAO, or even be aware of it. I'm not sure I understand the need to cerate a seperate DAO object just to map to a business object. It seems to be a lot of extra code with little benefit. You could probably simplify your solution by having one data gateway layer between the business objects and the database.