# 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

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