Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Is that a better way to inherit the Data Access Layer(DAL) in Business Logic Layer(BLL) instead of creating an object of DAL in BLL in any Object oriented language? However the DAL uses only protected methods & properties so that it is not 'visible' to other layers. Is this breaking n-tier architecture standard?
Posted

1 solution

No, it's better not to do that. Inheritance creates a far too strong dependence between the application logic and the data access logic. Just try to estimate the work involved when you have to rewrite the data access classes when migrating to another database. Instead, the DAOs should expose an interface which is used by the application logic. Then all you have to do is to write new classes that implement the interfaces of the DAOs and the application logic does not care where those objects come from and how they implement their interfaces.

In addition, you can always inherit only from one baseclass. What if some class in the application logic needs to use two or more DAOs? For example you could use one DAO to get a user's data and a second one to get the list of the user's roles, so that the application logic is able to check the user's permissions. Obviously the classes of the application logic don't always correspond to one single entity or its DAO.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900