mardi 6 décembre 2016

Multiple builder vs single builder pattern?

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.

How do I setup my builder pattern for this problem? It looks like I need to use composition here.

  • 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. Can anyone provide an example on this problem?

Aucun commentaire:

Enregistrer un commentaire