I create an interface for database access to a MySQL database
. Currently, this is the only way to access day, but to make it easier to test and in the event that the data access might change
, I used an interface, however, now I am faced with the dilemma of which methods I should put on the interface and which methods I should put on the concrete implementation
directly. Is there a rule of thumb for this? I will give an example below where I have some CRUD operations for a ICar
interface, but then some other utility functions that are just on the concrete implementation. Should these be on the interface as well? I wouldn't want a user to have to implement every method if they didn't need to?
interface ICar
{
Car GetCar(int id);
void DeleteCar(int id);
void InsertCar(Car car)
Car UpdateCar(Car car);
}
class Car : ICar
{
Car GetCar(int id)
{
}
void DeleteCar(int id)
{
}
void InsertCar(Car car)
{
}
Car UpdateCar(Car car)
{
}
// methods not on interface, but should they be
public string GetCarVIN(Car car)
{
}
public string GetCarColor(Car car)
{
}
public string GetCarMake(Car car)
{
}
public string GetCarModel(Car car)
{
}
public string GetCarOwner(Car car)
{
}
}
Aucun commentaire:
Enregistrer un commentaire