Separate decoding / encoding interfaces or one interface

I am creating an implementation that does the conversion from one form to another.

The design problem that I am facing right now is whether Encoder and Decoder API should be in the same interface or in separate ones. for example 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 placing them in one interface is that you can centralize implementations and fix any protocol changes in one place. Any thoughts on this?

+3
source share
8 answers

, . , , . , .

, , , , , . , , .

+6

, , , . , .

c/++ .. .

. .

+2

, , , , . , . , /?

+1

. , , , .

. , , .

+1

, , , . ,

private IEncoder encoder;
private IDecoder decoder;

public ThingWhichUsesEncodeAndDecode(IEncoder encoder, IDecoder decoder)
{
    this.encoder = encoder;
    this.decoder = decoder;
}

public ThingWhichUsesEncodeAndDecode(IEncoderDecoder both)
{
    this(both, both);
}

, , . , / , - .

0

, . , . BTW: , .

interface Converter extends Decoder, Encoder { }
0

, /,

interface Encodable
{
    Decodable encode();
}
interface Decodable
{
    Encodable decode();
}
class A implements Encodable;
class B implements Decodable;
0
source

Depends on the application.

If you usually use the encoder and decoder in the same binary format, one interface is fine. If they are usually separated (for example, only encoding a capture application, only decoding a control application), use separate interfaces.

-1
source

Source: https://habr.com/ru/post/1702178/


All Articles