How to have multiple builder pattern in a single builder class?
<p>I have two types of payload coming from upstream: It's either <code>PayloadA</code> or <code>PayloadB</code>.</p>

<p><code>PayloadA</code> containes these many fields:</p>

<pre><code>createTimestamp
sentTimestamp
schemaId
eventId
producerId
guid
deviceId
langId
sessionId
</code></pre>

<p><code>PayloadB</code> containes these many fields:</p>

<pre><code>createTimestamp
sentTimestamp
schemaId
eventId
producerId
eventType
payloadVersion
creationDate
expirationSeconds
payload
</code></pre>

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

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

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