Builder & decorator patterns together, am I doing this right? [closed]

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()), 'username', 'password', 'method' );$message = new Message();

$builder->build();$builder->buildText($message);$builder->buildEncoding($message);$builder->buildCharset($message);$builder->buildRecipients($message);$builder->buildSenderNumber($message);$builder->buildSenderString($message);$builder->buildValidity($message);$builder->buildDeliveryStart($message);$builder->buildUserReference($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.

-

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

• This question does not appear to be a code review request within the scope defined in the help center.
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 at 17:38

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

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