Note that there are some explanatory texts on larger screens.

plurals
  1. POGame player object design
    primarykey
    data
    text
    <p>I'm supporting a server for an online card game and while thinking about refactoring it into a better state I have found myself unable to decide what is a proper object model for my needs.</p> <p>I have a Player class which has a lot of attributes. The first problem is just that - the class is too big. The second problem is that I don't know how to refactor it. I will list some of the attributes and issues with these.</p> <p>Some attributes are very tightly bound to a player: nick, email, last login &amp;c. These, I suppose, are to be kept directly in the player class and in the same table in the DB.</p> <p>Now, some attributes are a little more difficult, like money and gold amount. The problem with these is that they are historically stored in a different table, there might be some more currencies later on and that they MUST be synched into the database at their own pace.</p> <p>Third category of attributes are loosely coupled to the player, like status string, experience, achievements, statistics &amp;c. These are stored in different tables in the DB and MUST be stored, retrieved, cached and synchronized at their own pace.</p> <p>Note that one of the big problems here is that we have to implement relatively complex database synchronization schemes because we have a lot of online players and our game is soft-realtime and we have to make load on the DB as low as possible.</p> <p>My questions are: </p> <ol> <li>How to determine which attributes to store within a player class and which not to? Say, experience, nickname, money amount?</li> <li>When one has some attributes that may be grouped together like (strength, agility, endurance, &amp;c.) and (handItem, headItem, feetItem, weapon) when they should be grouped and when not? </li> <li>What to do with complex database synchronization schemes? Make a separate model for each attribute that needs to be synched independently or make some DataManager classes to take them apart and work with them?</li> <li>What to do with the need for a class to have several different "data representations" for external consumers? Like XML, Json, another XML for some external service, human-readable string, &amp;c.</li> </ol> <p>I'm sorry if my questions are bogus, I'm not really good at OOP design, I'm more an FP guy. And my English is not very good =).</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. COI can't understand the parallel you make between the database and an object. It don't help. On one side you have a class witch is too big, that's one thing which belong to the "logic" part. On the other, you have the way data is stored in your database. Those two are not the same thing. Could you please detail how your player "class" is used ?
      singulars
    2. COYes, but the way data is stored is important for modeling. Basically, this Player class is a storage of different player attributes. It is a central class for all his actions. When player looses money, we find his account which is another class but is linked from within a player and withdraw money from it. Account has its own DAO which in turn works with database. Player also has Experience which is stored in a different class and has its own DAO and cache. Player is rendered to the client in the XML form where it gathers all of these attributes in one huge XML.
      singulars
    3. COWhat I don't understand is why you have to synchronize these tables. You may have to join these, but synchronize ? Database synchronization refers to keeping two or more separate databases up to date with each other's data changes. Where here have you two databases ? You have one in your cache ? I'll try to answer assuming this. If you posted a global layout, it would be easier to help you.
      singulars
 

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