title: Serialization and Composition
body: <p>Im having a BaseRecord class that represents a DBRecord which implements Serializable ..</p>
  
  <p>I need another DB trigger sortof functionality which would have its own data members=trigger activation event data => which when satisfied would insert a BaseRecord</p>
  
  <p>So my question is </p>
  
  <ul>
  <li>Should i use composition or inheritance here? I'd go for composition as its better saying TriggerRecord HAS-A BaseRecord i.e to be inserted when trigger activation event occurs..</li>
  <li>1 more thing is that BaseRecord implements Serializable, and user can depending on mode of operation can modify BaseRecords(eventually DB Records) <strong>AND</strong> modify TriggerRecord so i need methods of both BaseRecords(toString(), getters,setters, and other data modifications) and TriggerRecord(BaseRecords method alongwith trigger activation event data handling methods)</li>
  </ul>
  
  <p>So ..</p>
  
  <pre><code>class BaseRecord implements Serializable
  {
        ...
        ...
  }
  
  class TriggerRecord
  {
  EventData eventData;        //Non-custom Objects
  BaseRecord br;
  }
  </code></pre>
  
  <p>So my question </p>
  
  <ul>
  <li>whether should i use composition in this case? </li>
  <li>and is sending a TriggerRecord ArrayList by network serialization would be achieved automatically as all data members of TriggerRecord are Serializable or do i need to explicitly implement Serializable with SerialVersionUID?</li>
  </ul>
  
  <p>Edit 1:
  As of now TriggerRecord has only 1 Custom Object of BaseRecord, possibly adding more .. and essentially TriggerRecord is too another mapped to DB Record that has eventData and a different format for BaseRecord storage because it stores BaseRecords of more than 1 relations .. </p>
  
  <p>and if i extend BaseRecord then i'll have to use super.toString() to access BaseRecord's string representation..
  and i just tried with composition of BaseRecord inside a TriggerRecord .. it needs implements Serializable even if all data members are already Serializable .. so asking why is it necessary to explicitly implement Serializable for class that is composed of other Custom objects</p>