lundi 17 août 2015

Is "file" also participate in open closed principle?

I know according to open closed principle, something like class,interface,code.... should be unchanged when add new functions or contents, but is file also in this case?

I was designing a game, the game have some monster information, and the game (in client side) may download or replace some file if there are new monsters to add or update.

I was worrying what should be the format of monster information: 1 file with all monster information or each monster has individual file?

1.Store all monster information into a single file (e.g.:monsterlist.json),each time add new monster it will replace the file e.g.:

{  
    "monsterList":[
        {
            "id":1,
            "hp":100,
            "attack":230,
        },
        {
            "id":2
            "hp":500
            "attack":980
        }
    ]
}

2.Each monster has a individual file,each time add a new monster will also add a new monster json:

monster1.json

{
    "id":1,
    "hp":100,
    "attack":230,
}

monster2.json

{
    "id":2,
    "hp":500,
    "attack":980,
}

At start I think case 1 is most convenient, because when I add or update any monsters I only need to replace monsterlist.json, but for case 2, I need to know which json is new (may need extra row to store the update status in server database).

But suddenly I remember open closed principle, adding something new should not modify the current content, it seems not reasonable to replace a file when a new monster is added, should I use case 2 to store the monster information?

Aucun commentaire:

Enregistrer un commentaire