Team Queue

So, I have a database management program (sql) that I am working on when dealing with products that my company sells. For the main part of the program, product information is updated as the user goes through some user controls. Everything works perfectly. But now I am in a higher level section of the program that adds / removes / copies elements. It cannot be an β€œupdate on the fly”, for example, editing information on details, since it would be too easy to damage things very badly. Therefore, I basically want to create a file for them β†’ save transaction type. As I can see, this work creates all sql commands in the list and then runs them when saved.

The functions available here will be adding a new element, deleting an element, copying from another element and renaming.

So this will be a list like:

insert...
update...
update...
delete...
update...
etc.

He will execute all the commands and execute them. I already have a class that has methods for handling all of these functions. I can't think of a way to call all these methods in the queue, and rewriting all the sql statements in another class seems silly to me. Is there a way that I can remember a list of something like:

item.Rename()
item.ChangeSize()
item.Delete()

It seems to me that I am thinking too much about this ... or, perhaps, thinking ... I do not know.

+5
source share
1 answer

What you are looking for is this Command Pattern.

, ICommand, Execute().
ConcreteCommand, . a RenameCommand NewName.

, , , . , .

public interface ICommand
{
    void Execute();
}

public class RenameCommand : ICommand
{
    private string newName;

    public RenameCommand(string newName)
    {
        this.newName = newName;
    }

    void ICommand.Execute()
    {
        item.rename(newName);
    }
}
+6

All Articles