PDA

Click to See Complete Forum and Search --> : Anyone care to explain design patterns?



SJT
10-29-2003, 07:19 AM
I understand the basic concept of splitting the application up into sections that can independently do their job without knowing what they're interacting with.

I'm not sure I really get the whole idea of things like the the MVP pattern though...
i.e. why have two separate sections, the View and the Presenter, which basically both deal with user interaction?

aversion
10-29-2003, 09:10 AM
I always thought it was the Model View Controller MVC pattern, I haven't heard of MVP.

In the MVC system the model is where the application data is accessed, manipulated and stored, it should work independently of the other app components triggered by events and listeners, in flash it can be something like a custom class that is stored in an external .as file.

the view component is the front-end, the part that collects data and interacts with the user, like a form for example. These elements should be relatively free of code, not manipulating data in any way. The controller component is the code that sits within the flash movie, on the timeline, controlling the flow of data and handling user input and interaction with the model component, it makes the decisions about what to do, the model carries out the actions, and the view displays them appropriately.

I try to stick to these general rules when designing an app but inevitably it all gets a bit muddled once you're into the process and people change things around. I do try to centralise my code and use custom classes as the 'engine' of the app, but I need to learn more about using listeners as part of an application, I keep meaning to run through this article (http://chattyfig.figleaf.com/flashcoders-wiki/index.php?AsBroadcaster) when I have the time.

SJT
10-29-2003, 09:51 AM
MVP is an updated MVC apparently...model-view-controller makes more sense just in terms of naming to me, rather than model-view-presenter.


These elements should be relatively free of code, not manipulating data in any way
So the idea is that the form merely transmits the data, and the controller manipulates it; thus we can change the controller without affecting the view as long as the same interface is used...I see.
I think half the thing that was confusing me was the fact that Presenter and View seemed to conflict, calling it Controller makes more sense really.

Senocular has written a great article on listeners and broadcasters.
http://www.umbc.edu/interactive/flash/tutorials/showpage.php?p=ASBroadcaster

Thanks Av

aversion
10-29-2003, 12:47 PM
well, I've been doing a bit more research because I wasn't really aware of the MVP model, but you're right, it does seem to be gaining in popularity but also confusing a lot of people.

i found an interesting thread on design patterns over at digital illusion forum (http://www.digitalillusion.co.in/diforum/viewmsg2.asp?forumid=65&cname=13&messageid=2409&viewmessageid=2409&parentmsgid=0&fv=9&srep=15) and one link in particular was useful in defining this pattern.



Presenter

While a view is responsible for the output of model information to the user, a presenter's responsibility is to manipulate the model as a response to the users input. The user gestures (list selections, mouse movements, keyboard hits) are received by the view and passed to the presenter. Normally a presenter will maintain a selection that identifies a range of data in the model that is current, and the gestures received from the view will be used to act on this.

The presenter is allowed to know about both its view and model and this fits with its role as mediator between the two.

object arts (http://www.object-arts.com/EducationCentre/Overviews/ModelViewPresenter.htm)

so it seems like the presenter doesn't do that much differently from the controller in the MVC pattern, I think 'presenter' is a misnomer, a lot of people seem to be confused about the difference.

:|



some people seem to have trouble accurately representing design patterns in the flash environment and I think some of the object changes to MX2004 are addressing this. Flash's visual environment means that the view and controller components are both situated on the timeline, I'm not sure that they can be truely independent like this. But I don't think it's a big deal, I'm not losing any sleep. Like everything these are interesting guides.

Skinn3r
11-02-2003, 09:46 AM
I like this website:

www.phppatterns.com (http://www.phppatterns.com)