Data Layer, Model Layer and interfaces in Java
<p>Lets say we wish to represent a Person</p>

<pre><code>public interface Person {

    String getFirstName();

    String getLastName();

}
</code></pre>

<p>This is implemented with JPA (code I am missing out since it is pretty banal)</p>

<p>Now, I wish to have a Model, the interface of which is an extension of the person interface with setter methods</p>

<pre><code>public interface PersonModel extends Person {

    void setFirstName(String firstName);

    void setLastName(String lastName);

}
</code></pre>

<p>and I implement a concrete implementation of the Model interface (which I am skipping since its pretty banal again)</p>

<p>In doing this I realised that the PersonModel extending from Person doesn't really make that much sense since a "PersonModel is not a Person"</p>

<p>It is also not "correct" to cast a PersonModel to Person.</p>

<p>What is the correct way to implement this - PersonModel could just not inherit from Person and re-define the methods but that means extra maintenance.</p>

<p>I could extract the methods to another base interface -> PersonBase(?) and extend both Person (no other methods defined) and PersonModel from that.</p>

<p>If I am going down the above path, what would be the best way to name the base interface?</p>

<p>One of the main reasons I am using interfaces (apart from the fact that it helps me in thinking through about how everything would work / fit together) is so that there can easily be different implementation layers (JPA2/NoSQL Driver etc.)</p>

<p>This is not real code being used, so please excuse any syntax errors / typos - I just wrote it up for the purpose of this question.</p>

<p>Thoughts / guidance / advice appreciated.</p>

<p>Thanks,</p>

<p>Shri</p>
