Yes, as long you are coding with this style consistently and you are not relying on what they are. But in reality no, let's see why.
Let me make a short example, you get a Updatable interface
public interface Updatable
{
public void Update();
}
Now, there are many things that could get be updated, a sound system, a physics system, another algorithm. So there is nothing wrong to have the same interface even though those are very different. However things starts to change if you have to make assumptions internally, in example if you have also real life systems, like controlling real pipes in a chemical plant, you may want to avoid to open close valve continuosly when you are around equilibrium points, you will just wear valves more than needed. In that case maybe you want a Update every 2/3 minutes and not every half second.
Functionally the interface is the same, but you have to make distinction because of underlying implementation, regular updates (which is an anti-pattern anyway) and real-valve updates. At this point you'd better live with different interfaces
public interface TickingSystem
{
public void Update();
}
public interface PipeSystem
{
public void Update();
}
Resist the temptation to do this:
public interface TickingSystem: Updatable
{
}
public interface PipeSystem:Updatable
{
}
Which is conceptually wrong. Having the same methods, should not be an excuse to have the same interface, as long as it could be potentially used in different ways. A interface is a contract, so "this thing should be used in a certain way".
Eventually you may want to adapt a compatible interface to another compatible interface only for very few specific cases. In that case you take something that should be used like a Pipe, but is so technologically advanced that you get benefits using it as a TickingSystem, but you make that very clear in code, you are adapting something to be used as something else, and you are conscious that you should not do that.
public class FastPipeSystem: TickingSystem
{
public PipeSystem pipeSystem; // makes clear your are just using a interface
// accept just the specific types of pipes that can have very fast switching
public FastPipeSystem(MicroPipe yourFastPipe)
{
pipeSystem = yourFastPipe;
}
public FastPipeSystem(LazyValvePipeEvenIfFastInput yourFastPipe)
{
pipeSystem = yourFastPipe;
}
public override Update() //a ticker
{
pipeSystem.Update(); // that tick a pipe .. (that can be ticked!)
}
}
If you make a concrete example on your problem experts on stackoverflow will be happy to see if in your code you have one case or the other, but otherwise this is the most we can say.
Sometimes some interfaces are complex enough to allow to use different behaviours depending on some parameters
public interface ConditionallyUpdatableSystem
{
public int MillisecondsToWait();
public void Update();
}
In example such interface allows to select different behaviors depending on result of MillisecondsToWait
(in example 0 => continuos ticking, 120000 for pipes etc.)
But it is generally bad Idea, because it is really creating a fork where you can avoid the conditional jump just by using 2 specialized different types. Usually complex interfaces are for complex behaviors (and then someone lazily decide to use them for simpler behaviors). In example all interfaces of standard data containers are pretty rich, but someone is free to make simpler container and ignoring the richness of the interface, but at that point is ok, becuase the rich interface was the only viable alternative to resolve a problem. But making more complex interfaces for simple problems instead is generally a bad idea.
dispatch
orrun
function on each of them and doing away with theswitch
statement altogether?Runnable
class.