Command pattern: Interaction allowed?



In a command of the command pattern, would you say that interactions or
callbacks are allowed? E.g. if there is command 'Delete', is it okay if
the command calls a function that asks the user 'Are you sure?' and
then do the deletion or not? I guess this wouldn't be advisable since
it obscures the pattern somehow. Well, it is a simple example. The
assumed interaction could be more complex. Consider a dialog in an IDE
where one could choose which files to store when the user has clicked
on 'Close Project', i.e. the CloseProjectCommand is triggered.

However, when I think of the alternative it yields some disadvantage as
well. Consider the CloseProjectCommand: Before the command is actually
triggered the unsaved files have to be figured out, the dialog has to
be shown and some SaveFileCommands have to be called. And where would
be this logic for these steps? Would it be part of the business model?
It should, I guess, but I don't know how to realize this. From my point
of view this would be part of a 'higher' level, and this would be the
UI. What is not okay - I know.

Hm. Let me ask a further question: If it would be part of the business
model then the business model has to trigger the UI somehow (callbacks,
events, through an interface somehow), so e.g. the dialog for choosing
the files gets opened. Correct? Is this okay? Do you even think 'how
else should an application work?'. If so, sorry, for asking that.
Currently I assume that the UI triggers the business logic solely and
not vice versa. Is this wrong understood or is it an design that is
reasonable in certain applications? What would you say.

Thank you for your help.
Robert

.



Relevant Pages