On Nov 16, 1:37 am, "Brook Davies" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> This is a bit OT sorry, but I don't know where else to post this JS related
> question. My question is about using design patterns and OOP principles in
> Javascript.

You could try news:comp.lang.javascript

<URL: 
http://groups.google.com.au/group/comp.lang.javascript/topics?lnk=gschg&hl=en
>


> I am trying to determine the best way to build a photo album application,
> where the user can layout many photos and each photo can have different
> properties and behaviors. They can also add text and other elements to their
> photo album.
>
> Does it make sense to create a PhotoElement class for each photo added to
> the album? This might be instantiating between 10-200 of these objects. Each
> object would manage its own display, and properties etc.  The data would be
> saved back to the server and when it was reloaded, the data would be parsed
> back into object instances.
>
> So does that make sense, or should I just use a MVC pattern where the
> controller looks at the data (model) which is, say an array of objects (the
> photos/page elements) and creates an each instance of the photo
> representation (renders them to the screen only) and handles all of the
> interaction through conditional processing as opposed to allowing the
> objects to do their thing and maintain their own properties and behavior.

I would prefer the second approach as it requires a single handler on
the page which can be available essentially from the moment visitors
see any content.  It can see where actions come from and work out what
to do based on the class of the target element.

The first approach infers that visitors must wait until the page has
loaded, or you'd need to use a "domRead" handler (which is problematic
in some browsers) or a polling approach to detect images as they are
loaded.  I also think it's silly to instantiate a whole bunch of
objects when only a few of them will ever be required.

Others will disagree of course.  If you were creating a game with lots
of interactivity my opinion might be different.

--
Rob

Reply via email to