• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Command/Undo Pattern - How atomic should commands be?

 
Bob Dobalina
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all, I'm working on implementing a command/undo/redo system for a GUI. I'm going through the design now. Currently I'm splitting things into commands, and the way things are going I'm going to wind up with dozens and dozens of separate Command objects.

In general the GUI enables creation of different types of business-related objects, edits of those objects, and deletion of those objects. Multiply that times 15 different business object types and that's a lot of Command objects. I was looking for a little advice on whether it's better to make very specific Command implementations for each type of operation, or make more general but larger Command objects.

For example, should I have 15 separate "Delete" commands, each of which know how to do the deletion for a specific type of business objects, or should I have one big "Delete" command that has more complex internals to handle deletion of different actions depending on the business object being deleted?

Thanks,

-Bob
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, this sounds like a common problem that isn't just GUI related. Should I have more classes with less comlpexity or fewer classes with more complexity. My personaly opinion is to at least start out with more classes that contain less complexity. Doing it this way, I think you'll find it easier to see similarities between your commands and find ways to refactor them into few classes and/or interfaces. Where as if you had less classes with greater complexity, it begins to get difficult to really see where your similarities lie. Does that make sense?

I see a lot of people think that because they have a great number of class files they must be doing something wrong. And yes, sometimes they can be. But often times more classes means better code because you've done a better job of encapsulating your logic into meaningul, reusable chunks.
[ August 31, 2006: Message edited by: Gregg Bolinger ]
 
Bob Dobalina
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gregg, I hadn't thought of it on a more general OO-design type of scope. I'll continue down the path of inundating my diagrams with classes until I start to see enough overlap to narrow it down at all.

That said, if anyone else has any more experience to share, I'd love to hear it.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bob Dobalina:
Thanks Gregg, I hadn't thought of it on a more general OO-design type of scope. I'll continue down the path of inundating my diagrams with classes until I start to see enough overlap to narrow it down at all.

That said, if anyone else has any more experience to share, I'd love to hear it.


For what it's worth, I typically need to see the code to find sensible overlaps. UML diagrams are just too coarse grained to make such decisions, in my experience.

You might want to take a look at http://c2.com/cgi/wiki?FearOfAddingClasses
 
Campbell Ritchie
Marshal
Posts: 52574
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posted by Gregg Bolinger
this sounds like a common problem.
Agree. Have you looked through the books for an example?
There is one (in a book about Eiffel) in Meyer's quirky style, and I am sure you could find other examples in other books.
My example is:-
Inheritance case study: "undo" in an interactive system, ch21, in Meyer B[ertrand], Object-oriented Software Design, 2/e, Upper Saddle River NJ, ISE Inc (Prentice-Hall): 1997, pages 695-718.
I don't know how helpful you will find it, but it can't do any harm to look.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!