I know that the Specification pattern describes how to use a hierarchy of classes implementing ISpecification<T>
to evaluate if a candidate object of type T matches a certain specification (= satisfies a business rule).
My problem : the business rule I want to implement needs to evaluate several objects (for example, a Customer and a Contract).
My double question :
Are there typical adaptations of the Specification patterns to achieve this ? I can only think of removing the implementation of
ISpecification<T>
by my specification class, and taking as many parameters as I want in theisSatisfiedBy()
method. But by doing this, I lose the ability to combine this specification with others.Does this problem reveal a flaw in my design ? (i.e. what I need to evaluate using a Customer and a Contract should be evaluated on another object, like a Subscription, which could contain all the necessary info) ?