Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Little background: payload is the representation of a message being send, using a specific transport. The builder pattern is used to build different representation (as array, or as a Swift_Message object) of the same message.

But depending on the method used (basic, classic, etc...) and transport itself, some properties should be ignored (for example validity shouldn't be included if message is "basic"): here comes the decorator pattern, that decorates the builder itself (it's a builder).

Example: BasicPayloadDecorator has an empty implementation of buildValidity() method. The MethodGuzzleDecorator adds some authentication information to the array representation of the message (created by GuzzlePostDataPayloadBuilder).

For building an array representation of a "basic" message, adding authentication information:

$builder = new MethodGuzzleDecorator(
    new BasicPayloadDecorator(new GuzzlePostDataPayloadBuilder()),

$message = new Message();


/** @var $payload array */
$payload  = $builder->getResult();
$response = $transport->handle(payload);

Do you think I'm doing this right? I can't find any information about using the decorator against the builder. Here is the full diagram image. Thanks.


share|improve this question

closed as off-topic by Jamal Feb 21 '14 at 17:38

If this question can be reworded to fit the rules in the help center, please edit the question.

This question appears to be off-topic because it is a design and architectural review, not a code review. –  Jamal Feb 21 '14 at 17:38

1 Answer 1

I look more closely at the class diagram, and I think it's quite correct. The only thing I would add a factory that returns AbstractPayloadBuilder and contains logic about creating a set of specific decorators or return non-decorated object. Sorry for my carelessness

share|improve this answer
Yeah I'll think about it, but sure it will end up with an explosion of subclasses. –  gremo Nov 25 '12 at 18:02

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