I have a data provider project to access the database. this is composed by various classes (PersonDataProvider, JobDataProvider …)
I want to create an Interface.
Do I have to create an Interface for each class?
I was tempted to create one interface and than inherit on all the classes. This involves making all the projects classes partial and change the classes name…….But i think is not the best solution.
Any suggestion?
I have a data provider project to access the database. this is composed by
Share
You don’t inherit an Interface you implement it. There’s no need to make a class partial to add an interface to it.
An interface is a contract that the class subscribes to saying that it will honour the methods described in the interface and will implement them appropriately. For your scenario you’d create a single interface and implement it in your classes, you can then pass the instances of the various accessor classes as instances of the interface.
For example:
The data providers would then look as follows:
You can then pass the objects as IDataProvider as follows:
…
Hopefully that clears it up for you.