In one of my (Java) projects at work, we have an interface which represents the contents of a "savable window", which can be modified by the user, and where changes should be saved back to the underlying object when the user is done (usually indicated via an "OK" button).
The (vastly simplified) implementation looks like this:
/** Contains all
(
Read more... )
Comments 4
* Add the appropriate listener machinery to the Savable base class
* Create a new pure virtual (or abstract) method in Savable called doSave(), realSave(), or something similar.
* Rename the save() methods in all the Savable-derived classes to doSave().
* Change Savable.save() to be a non-virtual (or final) method that calls doSave(), then fires the SaveEvent.
Reply
* Add the appropriate listener machinery to the Savable base class
Just add this code to your main window Save() call
* Create a new pure virtual (or abstract) method in Savable called doSave(), realSave(), or something similar.
Rename your Saveable interface "save" method to doSave()
* Rename the save() methods in all the Savable-derived classes to doSave().
Same step works in java.
* Change Savable.save() to be a non-virtual (or final) method that calls doSave(), then fires the SaveEvent.
Final is a keyword in java your new Save method would look like this:
public final void Save()
{
//fire event code
doSave(); //calls proper virtual function
}
Reply
Sometimes the Savable objects call their own save(), so the CMWindow isn't always aware of when a save happens.(See Option #1.)
Final is a keyword in java your new Save method would look like this:Savable is an interface. AFAIK you can't add method implementations to an interface ( ... )
Reply
But suffice it to say that I'm duly impressed! ^^
Reply
Leave a comment