Note that there are some explanatory texts on larger screens.

plurals
  1. POIf not polymorphism, how do I model these classes
    primarykey
    data
    text
    <p>Ok so say I'm modelling the following Football Club: All people are Individuals. A Player is a person and therefore extends an Individual. A Member is a person and therefore extends an Individual.</p> <p>Superclass: </p> <pre><code>Individual {name, eyeColour} </code></pre> <p>Subclasses: </p> <pre><code>Player extends Individual {position} Member extends Individual {subscription} </code></pre> <p>Tom is the owner of the Football Club: </p> <pre><code>Individual i = new Individual("Tom", "Blue") </code></pre> <p>Bob &amp; Tony are Players:</p> <pre><code>Player p1 = new Player("Bob", "Green", "Goalkeeper") Player p2 = new Player("Tony", "Blue", "Striker") </code></pre> <p>Steve is a Member:</p> <pre><code>Member m = new Member("Steve", "Brown", 5.00) </code></pre> <p>Individuals, Players and Members are all persisted to the same Kind (Individual) in the GAE datastore using Objectify.</p> <pre> name eyeColour position subscription ^d Tom Blue [missing] [missing] Individual Bob Green Goalkeeper [missing] Player Tony Blue Striker [missing] Player Steve Brown [missing] 5.00 Member </pre> <p>What if e.g. Bob decides to become a Member as well as a Player? I want to store is subscription. I can't upcast Bob to an Individual and then downcast to a Member. Java doesn't allow this. I can't create a new Member and copy all the properties of Bob's Player object and store it back with the same id - I'll lose his Position property. I need Bob to be both a Member and a Player in the datstore but NOT in object form (I'm not after multi-inheritance) I still want to get(Player.class,"Bob") and have a Player object or get(Member.class,"Bob") and have a Member object. I won't need an Object that has both the position and subscription properties at the same time.</p> <p>I also want to avoid this is the datastore:</p> <pre> name eyeColour position subscription ^d Tom Blue [missing] [missing] Individual Bob Green Goalkeeper [missing] Player Bob Green [missing] 10.00 Member Tony Blue Striker [missing] Player Steve Brown [missing] 5.00 Member </pre> <p>because Bob now has data duplication on name and eyeColour which could lead to data inconsistancy.</p> <p>Any ideas for how to model this?</p> <p>Also what if Tom becomes a player, or Steve becomes a member?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload