Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What would be the best design pattern for this problem:

I have an Object A. Object A can either be registered or deleted from the database depending on the user request.

Data validation is performed before registration or deletion of the object. There are a set of rules to be checked before the object can be registered and another set of rules for deletion. Some of these rules are common for both operations.

So far, I think the Chain of Responsibility design pattern fits the most but I'm having trouble implementing it.

share|improve this question
2  
Why do you think the Chain of Responsibility design pattern is the best fit? –  Adam Zuckerman Apr 3 at 5:15

1 Answer 1

As described, I would probably implement an option type. That way I could return a "None" or a validated value (perhaps lazily) but that's an implementation detail and leads nicely to the idea of using a Decorator.

Decorator Pattern

Of course if the interface becomes ugly I would use a facade.

share|improve this answer
    
Decorator would work, but I usually think of Decorator pattern as something to be used when you want to transform the output into input for another class to use. In this case you'd simply be validating. I think chain of responsibility may work better imho. –  Neil Sep 30 at 7:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.