开发者

Example of Command pattern in context of a non-AJAX website

开发者 https://www.devze.com 2023-01-16 23:12 出处:网络
I have seen numerous examples of the Command pattern But they all tend to be in the context of a desk-top application.

I have seen numerous examples of the Command pattern

But they all tend to be in the context of a desk-top application.

i.e "Command decouples the object that invokes the operation from the one that knows how to perform it"

In the context of a pure HTML (but Zend Framework MVC driven) website, I am thinking of a user 'clicking a link' which should refresh the current page and invoke a certain command. No matter which page of the site the user is on.

An example would be, in a blogging app:

i.e

To be able to present an HTML form button/s to, say, "Delete Blog Post" on both:

  • 'List Page' (lists blog posts)
  • 'Edit Page' (edits a blog post)

  • The form action on the 'List Page' points to 'List Page'

  • The form action on the 'Edit Page' points to 'Edit Page'

I suspect the Controller part of the ZF MVC is kind-of a command pattern. However, that routes URLs to a particular controller. I a开发者_如何学运维m trying to ALSO route command actions to particular command receivers at the same time.

Does the command pattern apply here or is it only really useful in the context of rich graphical user interfaces - such as desk-top apps or AJAX-enabled sites?


I'd say that is does not apply here and that it over complicates something that can be achieved pretty simply using ZF's partials.

Creating an object for all buttons or even a button seems over kill for a web application? The presence of the button should be based on your ACL, eg does the user have sufficient permissions to have access to this button. The same ACL check should of course be done on the URL that the button points to.

0

精彩评论

暂无评论...
验证码 换一张
取 消