|
IDE : VS 2008,
Platform : .NET 3.5, Hi, I typically dont create interfaces unless i have to, however in my current application i have to create interfaces in the Data access layer. I'm a in a minor confusion that hwo do i create those interfaces more how to implement them: the following code might make things clear: I have the following class and interface in the data access namespace |
|
1. Is this way implement the interface in the data access layer? (in this case the class CountryGateway access the database.) i.e: That we should create interfaces to access DB in the DAL and then we should also write the implementation for those interfaces in the DAL?
2. I have been told that we should create interfaces than abstract classes espcially in the data access layer, is there a particular reason for this?
Dushan StankovicPosted Sep 21, 2009, 3:08 PM
But in this post Petre asked us about interfaces, I must sad interface classes, and it's usage. You are so right about complexity of interfaces like public stuffs in DAL, and guy in CodeProject do simplify that.
That is in .NET 2.0, and in 3.5 or grater we have LINQ and auto generated classes for more easier DAL developing. Thanks for that :), but always is good to know to implement our own mechanism.
Master BillaPosted Sep 19, 2009, 11:14 PM
yes your way correct, but there issues, see interface are would come as common. it's should base on your every object base.
See here great sample code implemented common way interface and implemeted
http://www.codeproject.com/KB/database/Lightweight_DAL_in_NET_2.aspx
thank you
Dushan StankovicPosted Sep 19, 2009, 4:49 AM
If you creating some service project, like WCF, you must use interfaces because they are Service Contract for endpoints.
In Console app, or WinForm app, I use interface if entitys in my database have a same behavior i.e. Car and Truck (Car is vehicle, is Steerable, may start and stop, .... like Truck) and with interface I define public stuff for all same class but implement that stuffs in particular classes.
Because you can use interface like this:
IDrivable myD = new MyCar() as IDrivable;
it is easy to use one instance for different classes.
This is basic for the interface usage, if you need more continue this post.
Don't forget to mark "DO YOU LIKE ANSWER" if I helped you, Thank you :)