开发者

Composite pattern confuses me

开发者 https://www.devze.com 2023-01-17 05:39 出处:网络
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.

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

精彩评论

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