|
Prev: State of the Art Software Development Practices
Next: Difference between Factory and Abstract Factory
From: Robert Schneider on 23 Mar 2007 07:46 I have a common scenario: My application is currently based on files which contain serialized data. The business object that are created somehow (file loaded or new objects created). Now the user wants to save into a file. He does this and then manipulates some data. Then he wants to close the application. The question comes up: Hey, don't you wanna save your data? Now, how should the application detect that something has changed? What would you recommend? I could imagine three approaches: 1. Event-based: Each business object provides an event 'Modified' which would be observed from someone (not sure who should do this) 2. A global function 'ModificationsWereDone' with a boolean variable that can be queried. In every place where the model could get modified this function has to be called. 3. Serialize the data and compare the result with the former serialization output (if there was one). I don't like approach 1 and 2 because it looks error prone and it results in so many calls what also reduces the performance of the application a bit. But maybe this is the general implementation in other apps? I don't know, that's why I'm asking. Approach 3 sounds better. However, I could imagine that this takes to much time if there is enough data. When I look at other applications (lets think of an Office Application) I have never seen that it takes much time to determine if something was modified or not. So I'm afraid this approach is a uncommon solution. Are there any other ways? What would you recommend? Cheers. Have a nice weekend. Robert
From: Dmitry A. Kazakov on 23 Mar 2007 09:12 On 23 Mar 2007 04:46:52 -0700, Robert Schneider wrote: > I have a common scenario: My application is currently based on files > which contain serialized data. The business object that are created > somehow (file loaded or new objects created). Now the user wants to > save into a file. He does this and then manipulates some data. Then he > wants to close the application. The question comes up: Hey, don't you > wanna save your data? > > Now, how should the application detect that something has changed? > What would you recommend? I could imagine three approaches: > 1. Event-based: Each business object provides an event 'Modified' > which would be observed from someone (not sure who should do this) > 2. A global function 'ModificationsWereDone' with a boolean variable > that can be queried. In every place where the model could get modified > this function has to be called. > 3. Serialize the data and compare the result with the former > serialization output (if there was one). 4. all mutators take care of the object's: 4.a. Modified flag 4.b. last modification timestamp 4.c. unique ID 4.d. hash value of the object's state The idea is similar to 3 in making the object responsible to determine whether two states are different. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: H. S. Lahman on 23 Mar 2007 11:49 Responding to Schneider... > I have a common scenario: My application is currently based on files > which contain serialized data. The business object that are created > somehow (file loaded or new objects created). Now the user wants to > save into a file. He does this and then manipulates some data. Then he > wants to close the application. The question comes up: Hey, don't you > wanna save your data? > > Now, how should the application detect that something has changed? > What would you recommend? I could imagine three approaches: > 1. Event-based: Each business object provides an event 'Modified' > which would be observed from someone (not sure who should do this) > 2. A global function 'ModificationsWereDone' with a boolean variable > that can be queried. In every place where the model could get modified > this function has to be called. > 3. Serialize the data and compare the result with the former > serialization output (if there was one). The answer is (2). However, one sets the variable in the setters for the relevant data, not at all the places where the setters are invoked. That's the only way to ensure data integrity for persistence. Presumably the variable is owned by the object that understands how to save the data so that object can reset it when the data is actually saved. [FYI, this sort of setter-based synchronization is quite common in communications between subsystems. When different subsystems abstract the same underlying problem space entity those abstractions may share some of the same attributes. In that case data integrity requires that their shared values be synchronized. So the setters for the primary data "owner" also send messages to the relevant subsystems (think: Observer pattern) with the new value. This is known as "implicit bridging" between subsystems because it is usually implemented automatically by full code generators rather than being explicit in the subsystem OOA models. That is, the application developer only has to indicate which attributes are shared in an MDA Marking Model and the transformation engine does the rest.] ************* There is nothing wrong with me that could not be cured by a capful of Drano. H. S. Lahman hsl(a)pathfindermda.com Pathfinder Solutions http://www.pathfindermda.com blog: http://pathfinderpeople.blogs.com/hslahman "Model-Based Translation: The Next Step in Agile Development". Email info(a)pathfindermda.com for your copy. Pathfinder is hiring: http://www.pathfindermda.com/about_us/careers_pos3.php. (888)OOA-PATH
From: topmind on 24 Mar 2007 02:02 On Mar 23, 4:46 am, "Robert Schneider" <tailorm...(a)gmx.net> wrote: > I have a common scenario: My application is currently based on files > which contain serialized data. The business object that are created > somehow (file loaded or new objects created). Now the user wants to > save into a file. He does this and then manipulates some data. Then he > wants to close the application. The question comes up: Hey, don't you > wanna save your data? > > Now, how should the application detect that something has changed? > What would you recommend? I could imagine three approaches: > 1. Event-based: Each business object provides an event 'Modified' > which would be observed from someone (not sure who should do this) > 2. A global function 'ModificationsWereDone' with a boolean variable > that can be queried. In every place where the model could get modified > this function has to be called. > 3. Serialize the data and compare the result with the former > serialization output (if there was one). > > I don't like approach 1 and 2 because it looks error prone and it > results in so many calls what also reduces the performance of the > application a bit. But maybe this is the general implementation in > other apps? I don't know, that's why I'm asking. > > Approach 3 sounds better. However, I could imagine that this takes to > much time if there is enough data. When I look at other applications > (lets think of an Office Application) I have never seen that it takes > much time to determine if something was modified or not. So I'm afraid > this approach is a uncommon solution. > > Are there any other ways? What would you recommend? > > Cheers. Have a nice weekend. > Robert It sounds like perhaps you should use a database of some sort rather than keep stuff for a long time in RAM (app variable-space). Use a task-based design approach where you focus on one task at a time and do any saving at the end of the task. Methodologies that encourage keeping stuff floating around in app variable-space for long periods is often poor design in my opinion. It makes app variable-space into a roll-your-own database of sorts, something it is not very good at. Keep the "business noun model" in the database, not in lingering app structures. Bad books tell people to do such, but such books should be burned. -T-
From: jaguaracisilva on 26 Mar 2007 05:39 On Mar 23, 8:46 am, "Robert Schneider" <tailorm...(a)gmx.net> wrote: > I have a common scenario: My application is currently based on files > which contain serialized data. The business object that are created > somehow (file loaded or new objects created). Now the user wants to > save into a file. He does this and then manipulates some data. Then he > wants to close the application. The question comes up: Hey, don't you > wanna save your data? > > Now, how should the application detect that something has changed? > What would you recommend? I could imagine three approaches: > 1. Event-based: Each business object provides an event 'Modified' > which would be observed from someone (not sure who should do this) > 2. A global function 'ModificationsWereDone' with a boolean variable > that can be queried. In every place where the model could get modified > this function has to be called. > 3. Serialize the data and compare the result with the former > serialization output (if there was one). > > I don't like approach 1 and 2 because it looks error prone and it > results in so many calls what also reduces the performance of the > application a bit. But maybe this is the general implementation in > other apps? I don't know, that's why I'm asking. > > Approach 3 sounds better. However, I could imagine that this takes to > much time if there is enough data. When I look at other applications > (lets think of an Office Application) I have never seen that it takes > much time to determine if something was modified or not. So I'm afraid > this approach is a uncommon solution. > > Are there any other ways? What would you recommend? > > Cheers. Have a nice weekend. > Robert Hello Robert, try to use a 4 option, AOP (Aspect-oriented Programming). The AOP separates the interess in a each Aspect and is fast to developer. Look this website: aosd.net (no www) and sees a compiler for your programming language and more information about it. Good lucky! Jaguaraci Silva
|
Next
|
Last
Pages: 1 2 Prev: State of the Art Software Development Practices Next: Difference between Factory and Abstract Factory |