vendredi 29 avril 2016

is it appropriate to use Reflection in this example

I am asking your opinion on this matter because I am not sure I should be using reflection in this scenario.

The scenario is that I have a table that I need to find out whether is on a dirty state or not. If a user makes changes into the table and then navigates away into another page without saving the changes... a warning message should pop up saying "Unsaved changes will be lost".

The approach I am using is to create a flag that is set to true if the table is dirty and false otherwise. When the user navigates away, without saving the table, by clicking on a link (a link that takes him to another site) the warning message pops up. On the other hand, if the user saves the table before navigating away then no warning message appears.

Issues that might occur if I make the dirty flag static is that another user can encounter the flag in a state that it shouldn't be. Since the static variable is bound to the class, every time I check this variable, the value of this field will be shared across every user in the application, isn't it?

On the other hand, however, if I don't make it static and use it as a member variable then, when I instantiate the object through reflection, it is going to return the default values. False if Boolean, null if String and or which ever value is initialized as.

This leads me to the conclusion that Reflection is not the best option to use in this example ?

I look forward to hearing from you, your opinion/view is very much appreciated.

Thank you very much.





Aucun commentaire:

Enregistrer un commentaire