开发者

Composite pattern confuses me

I have a few different types of validator classes that i am using at the moment all implementing a validator interface. Occasionally i require combinations of them but usually i need them individually. Does开发者_Go百科 this sound like a good situation to use the composite pattern?


Could be, based on the minimal information you provide.

You could implement a Validator which contains a collection of other validators, and uses all of the child validators to validate the given data.

As an extension/alternative, you could also implement logical operations via this pattern, e.g. Validators which AND / OR / XOR etc. the result of two (or more) child validators.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜