I am looking to minimize the number of code changes when I have to update interfaces in my classes.
I know about "just creating a new interface" to provide new functionality, but then I have to update all of the old interface references in my code to use the new one.
What I'd like to know is this a better idea than creating a new interface and updating all references
Let's say I start out with this:
public interface iMyWaiter : iMyWorker
{
void takeOrder();
}
Of course my class looks like this and I am not going to show all methods and properties in the class as they are not germane to the topic at hand.
public class MyWaiter : MyWorker, iMyWaiter
{
}
now let's suppose I want to update iMyWaiter to version 2, the "normal" way to go about doing that is to create a new interface:
public interface iMyWaiter2 : iMyWaiter
{
void getBill();
}
and derive the class from the new interface:
public class MyWaiter : MyWorker, iMyWaiter2
{
}
That incurs a cost of searching for the references of iMyWaiter and replacing it with iMyWaiter2
iMyWaiter waiter = new MyWaiter();
waiter.takeOrder();
now becomes:
iMyWaiter2 waiter = new MyWaiter();
waiter.takeOrder();
What I am thinking about doing is making a generic "iWaiter" interface that derives from the versioned one and a generic class that derives from the versioned one:
public interface iMyWaiter_1 : iMyWorker
{
void takeOrder();
}
public class MyWaiter_1 : MyWorker, iMyWaiter_1
{
}
public interface iWaiter : iMyWaiter_1
{
}
public class MyWaiter : MyWaiter_1, iMyWaiter
{
}
now when I need to update my interface, I simply squeeze the new one in between the generic interface and the last version:
public interface iMyWaiter_1 : iMyWorker
{
void takeOrder();
}
public class MyWaiter_1 : MyWorker, iMyWaiter_1
{
}
public interface iMyWaiter_2 : iMyWaiter_1
{
void getBill();
}
public class MyWaiter_2 : MyWaiter_1, iMyWaiter_2
{
}
so essentially this interface and class are always available to create and my code never changes, except to use new functions exposed by the new interface
public interface iWaiter : iMyWaiter_2
{
}
public class MyWaiter : MyWaiter_2, iMyWaiter
{
}
now I can simply add the "getBill" function to my code and not worry about interfaces:
iMyWaiter waiter = new MyWaiter();
waiter.takeOrder();
waiter.getBill();
My questions:
Is this a good design practice?
What are the downsides ?
What am I not considering?