On Jul 22, 8:27 am, "Aaron Gray" <ang.use...@gmail.comwrote:
I am after opend source small, middle or large example programs thay use MVC
pattern coded Javascript.
The traditional Smalltalk MVC does translate to JavaScript reasonably
easily. Whether or not a naive translation is a good idea is a big
question. I don't think it is.
Having a Data Access Layer (DAL) to encapsulate all the
XMLHttpRequests is a good idea. This layer is the only layer that
knows anything about HTTP or any other types of communication. This
layer can do some processing on the returned data from the server to
comply with the DALs stated API.
Having a Model layer is a good idea. This is the only layer that talks
with the DAL. The model layer knows business logic and implements the
observer pattern.
The part of MVC that causes me pause in the browser is the VC
distinction. I don't really think they are very clearly separated. The
main issue is how the strategy pattern part of MVC will be
implemented. Because JavaScript objects are dynamic, you can replace
property function-values of an object. This is something you cannot do
in Java for example. I don't know about Smalltalk. So in JavaScript
instead of replacing a reference in the view layer to a controller
object, you can just replace a particular function of the view object
itself. Also I don't find I take advantage of the strategy pattern
part of MVC frequently.
I usually design a program as
DOM
===========================
Widget |
------------| bootstrap.js
Model |
---------------------------
DAL
===========================
Server
The bootstrap.js file starts the feature testing, calls the Model to
populate itself, calls the widgets to start themselves and sends
references where the widget should insert itself in the DOM and
references to models the widget should observe.
It isn't so important that the layers do what the the traditional
"MVC" says they should. What is important is that each layer does what
its documentation says it does. For a very simple little widget the
three JavaScript layers could all be combined into one object.
Colin Moock's "Essential ActionScript 2.0" has a good discussion of
MVC. The best one I have read. The code is not in JavaScript, of
course, and he is very keen on classes but it is an indication of how
programmers will likely start writing code with ECMAScript 4. I won't.
The site of all those interface definitions. Ugg. You can download
that code from his site. Chapter 18 and some chapters around it will
likely be your interest.
"MVC" doesn't seem to be a big thing in browser scripting. That could
mean it isn't very useful or comes in such a different shape it is not
called "MVC". I think that usually MVC is just too heavy for the
requirements in the browser.
Peter