mercredi 28 septembre 2022

How to mark the modified fields in a class to be dirty

I have a class try to follow the active record pattern

class MyActiveRecord {
    int id;
    string name;
    int progress;
    ...
}

When I try to use this class to update the corresponding row of the SQL Data base, I want to mark the modified field to be "dirty". So, only the modified field, let's say progress will update the progress column in the data base.

My question is how to mark the modified field(s) to be dirty?

One way is to create booleans:

class MyActiveRecord {
    int id;
    boolean id_dirty;
    string name;
    boolean name_dirty;
    int progress;
    boolean progress_dirty;
    ...
}

Another way is to create enums of the fields and having a HashSet to contain the modified field enums.

Which way is better? Or is there another better way to mark the modified field(s) to be dirty?

Aucun commentaire:

Enregistrer un commentaire