mercredi 26 août 2015

Instantiating objects that need to be injected with Bridge (pattern) objects. How should I do it?

The context is the following:

I have Job class that represents a Job that is sent to a Job Queue. Currently we only use SQS for that purpose, but in the future we might migrate to Redis or another MQ solution. So currently, I have a AbstractJob that can be extended into ConcreteJobOne and ConcreteJobTwo, and can be consumed by AbstractQueueClient (which can be SqsQueueClient). I need a way of getting the payload from a Job object, what I came up was using the bridge pattern.

$parameters = [];
$sqsClient = new AbstractQueueClient();
$jobOne = new ConcreteJobOne($parameters, new SqsPayloadBridge());
$sqsClient->queueSingleJob($jobOne);

With that, I'm able to change the way I can build the payload for a specific client.

But the Controller that takes care of queueing that job has to know about SqsPayloadBridge and all the other bridges that might come in the future. I thought about using the Factory pattern to solve this but seems like overkill.

Any thoughts?

Aucun commentaire:

Enregistrer un commentaire