Click here to Skip to main content
15,915,328 members
Home / Discussions / C#
   

C#

 
Questionhow to listen windows net send service Pin
Nkuttynasi28-Mar-07 8:15
Nkuttynasi28-Mar-07 8:15 
AnswerRe: how to listen windows net send service Pin
Arjun "Mjolnir" Bahree28-Mar-07 10:08
Arjun "Mjolnir" Bahree28-Mar-07 10:08 
GeneralRe: how to listen windows net send service Pin
Nkuttynasi2-Apr-07 2:34
Nkuttynasi2-Apr-07 2:34 
QuestionProblem populating ListView by a CSV file? Pin
Khoramdin28-Mar-07 7:45
Khoramdin28-Mar-07 7:45 
AnswerRe: Problem populating ListView by a CSV file? Pin
J$28-Mar-07 9:24
J$28-Mar-07 9:24 
QuestionHe only had a toothache? Um... Dog.Euthanize.Undo()... Pin
Edmundisme28-Mar-07 7:29
Edmundisme28-Mar-07 7:29 
AnswerRe: He only had a toothache? Um... Dog.Euthanize.Undo()... Pin
led mike28-Mar-07 8:06
led mike28-Mar-07 8:06 
AnswerRe: He only had a toothache? Um... Dog.Euthanize.Undo()... Pin
Leslie Sanford28-Mar-07 8:14
Leslie Sanford28-Mar-07 8:14 
Edmundisme wrote:
This architecture is working really well but it has one flaw. Every time an engineer executes a command he is responsible for managing command history (i.e. the undo/redo stacks). If the execution is successful, he MUST add the command to the undo stack. If the execution fails, he MUST NOT add the command to the undo stack. If the execution throws an exception, he MUST CLEAR THE STACK as we cannot allow the undo stack at any time to be out of sync with the application state (this logic is somewhat simplified for the purposes of this post).

If the engineer forgets to do any of these things he poses a risk of undefined behavior in the application. Furthermore, the logic will be the same for every command that gets executed, so there’s no need to write this command-history-management-logic every time a command is executed.

In steps the factory pattern. The factory encapsulates the creation of commands. Because the factory controls the creation of the commands, it can setup a relationship between the UndoManager class (manages command history) and each command that gets created. Voila!


I was about to suggest that the logic for managing the undo stack be placed in the commands, i.e. when a command is executed, it's responsible for placing itself on the undo stack (or not depending on the results). But it sounds like you've solved this problem?

Edmundisme wrote:
Now here’s my problem (and perhaps it’s not a problem at all. Perhaps this is where I’m rubegoldberging). Any engineer can create a command and execute it. If the UndoManager class has no knowledge of this command, he cannot manage it and the undo history could get out of sync with the application state. Obviously this is really bad.


Underlying the commands is a document of some type that is being acted upon, correct? You're concern is that rogue command objects can be created that execute an action against a document. Being rogue command objects, they're not being managed, so they're never placed on the undo stack? As a result, a document's history could become corrupted.

The question is how could a rogue command object obtain access to the document in the first place?

I haven't looked at GOF in awhile regarding the Command pattern as it's applied to undo functionality, so I'm not sure how they implemented it. But how about the document itself being responsible for creating commands. The document has several private Command classes that implement an interface. And perhaps the document holds an UndoManager object for managing the commands.

When a client wants to execute an action against a document, they first ask for the appropriate command. The document gives them back a command it has created and is responsible for. The client, however, only sees the command object through some generic interface. This approach makes rogue commands impossible.

Edmundisme wrote:
To solve this problem, I have nested a private UndoManager class in the command factory. This class implements the IUndoManager interface. All commands require an IUndoManager at construction. So, because the UndoManager is private to the factory, only the factory can create commands. For example, to create a generic command:

public ICommand GetGenericCommand()
{ return new GenericCommand(this.undoManager); }


This may be close to what I've suggested above, I'm not sure. I need to know more about how the actual document, or model, is being used by the commands.
GeneralRe: He only had a toothache? Um... Dog.Euthanize.Undo()... Pin
Edmundisme28-Mar-07 8:26
Edmundisme28-Mar-07 8:26 
QuestionGNU license question (version 2) Pin
kamPooh28-Mar-07 6:14
kamPooh28-Mar-07 6:14 
AnswerRe: GNU license question (version 2) Pin
Stanciu Vlad28-Mar-07 8:20
Stanciu Vlad28-Mar-07 8:20 
GeneralRe: GNU license question (version 2) Pin
Wayne Phipps28-Mar-07 9:25
Wayne Phipps28-Mar-07 9:25 
GeneralRe: GNU license question (version 2) Pin
kamPooh28-Mar-07 15:34
kamPooh28-Mar-07 15:34 
GeneralRe: GNU license question (version 2) Pin
Nathan Addy28-Mar-07 15:52
Nathan Addy28-Mar-07 15:52 
QuestionHow to delete PDF files after viewing Pin
AndrusM28-Mar-07 5:50
AndrusM28-Mar-07 5:50 
QuestionAdapting form size to content size Pin
sinosoidal28-Mar-07 5:45
sinosoidal28-Mar-07 5:45 
AnswerRe: Adapting form size to content size Pin
Obaid ur Rehman28-Mar-07 7:43
Obaid ur Rehman28-Mar-07 7:43 
AnswerRe: Adapting form size to content size Pin
Arjun "Mjolnir" Bahree28-Mar-07 10:20
Arjun "Mjolnir" Bahree28-Mar-07 10:20 
AnswerRe: Adapting form size to content size Pin
Arjun "Mjolnir" Bahree28-Mar-07 10:21
Arjun "Mjolnir" Bahree28-Mar-07 10:21 
GeneralRe: Adapting form size to content size Pin
sinosoidal28-Mar-07 23:25
sinosoidal28-Mar-07 23:25 
QuestionMaximized child MDI form Pin
sinosoidal28-Mar-07 5:39
sinosoidal28-Mar-07 5:39 
Questiondisplaying images from a xml file Pin
diducmy28-Mar-07 5:35
diducmy28-Mar-07 5:35 
AnswerRe: displaying images from a xml file Pin
Martin#28-Mar-07 5:56
Martin#28-Mar-07 5:56 
QuestionXmlSerializer and CDATA Pin
theJazzyBrain28-Mar-07 5:15
theJazzyBrain28-Mar-07 5:15 
QuestionConverting a string to currency format Pin
lee.hallows28-Mar-07 5:09
lee.hallows28-Mar-07 5:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.