vendredi 23 octobre 2015

Design patterns for a serial of operations then commit

Saying I have a serial operations to update the data of a UI, like add(), delete(), update(), clear(). Those operations can be combined and permuted to show specific result. And notice that after all of those operations, I have to commit() changes (call notifyDataSetChanged() in my case) to make UI update.

The following is what I design to solve this problem.

public UIAdapter add(Data d) {
    ...
    return adapter;
}

public UIAdapter clear() {
    ...
    return adapter;
}

// for example
public void onClick() {
    fragment.clear();
    fragment.add(new Data())
        .notifyDataSetChanged();
}

But I have to remember to 'commit changes' every time I update UI and it's somewhat tedious.

Q: So I wonder if there exists better design patterns to solve this problem?

Aucun commentaire:

Enregistrer un commentaire