I’m creating an implementation that performs conversion from one form to another.
The design problem I am facing now is whether the Encoder and Decoder API should be in one interface or in separate ones. e.g. Apache MINA uses separate interfaces
I am currently doing something like this:
interface Convertor { A encode( B b ); B decode( A a ); }
The rationale for putting them in one interface is that you can centralize the implementations and fix any protocol changes in one place. Any thoughts on this ?
Having separate interfaces doesn’t mean you can’t centralize the implementation. For example you could have one class implement both interfaces. Or each class could reference a common class which implements the protocol.
So what I’d do is have separate interfaces, and at least to begin with, have one class implement both. So the implementation is shared, but user code sees the encoder and decoder as separate and independent concepts.