开发者

Choosing Design Pattern

I am writing a component to parse data collected from various devices. Basic purpose and set of commands that these devices operate are same, the difference is the size and formatting of the data. So planning to write three parsers but the component should support dynamic support for other devices also. For example

interface IPayloadParser
{
    public void ParsePayload1(byte[] payload);
    public void ParsePayload2(byt开发者_Go百科e[] payload);
    ...
    ...
    public void ParsePayloadn(byte[] payload);

}

is the contract that the parsers will implement. Selection of the parser is based on the type of device so thinking of using Factory Pattern to create the Parser and to implement the parsers, I am thinking of using Strategy pattern. Is this the right choice or should I use Template pattern here?


I think the Strategy pattern is a good fit.

See http://en.wikipedia.org/wiki/Strategy_pattern

The key factor is the requirement to choose the implementation at runtime based on the device, which you have.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜