lundi 5 décembre 2016

How to have multiple builder pattern in a single builder class?

I have two types of payload coming from upstream: It's either PayloadA or PayloadB.

PayloadA containes these many fields:

createTimestamp
sentTimestamp
schemaId
eventId
producerId
guid
deviceId
langId
sessionId

PayloadB containes these many fields:

createTimestamp
sentTimestamp
schemaId
eventId
producerId
eventType
payloadVersion
creationDate
expirationSeconds
payload

So first 5 fields are common between them. And in general they will have more fields.

I want to create a thread safe builder pattern for this. So should I have one Payload builder pattern class with all the fields from both the payload combined in it? Or I should have PayloadA and PayloadB builder pattern class inside another Payload builder class and the common fields of PayloadA and PayloadB will be part of Payload class?

What is the best way to make a builder pattern for this kind of problem. Let's say for PayloadA builder pattern deviceId is mandatory field. And for PayloadB builder pattern eventType is mandatory field.

Aucun commentaire:

Enregistrer un commentaire