Quick design question. I am trying to get a better understanding of Prototype. While reading through the source I am stumped by form.js. There is a "Field" object and a "Form.Element". Both object seem to consists of a series of actions that making interacting with form fields easier. My question is why two objects? It seems that there should be one object that has this functionality. Is there a design reason behind this? Or is it just because of historical accident? They seem to have overlapping purposes. I couldn''t determine the reason for myself so I figured I would go to the source. Eric
This is just my opinion, but after looking at the code I would say that Form.element has a lot more to do with the retrieving data (serialize, getValue) and Field has a lot more to do with the state of the field (clear, focus, select, etc). I guess in the end it doesn''t really matter because they are static methods. But you are right there is no functional reason to split them up. Nicholas On 5/11/06, Eric Anderson <eric-ANzg6odk14w@public.gmane.org> wrote:> Quick design question. I am trying to get a better understanding of > Prototype. While reading through the source I am stumped by form.js. > There is a "Field" object and a "Form.Element". Both object seem to > consists of a series of actions that making interacting with form fields > easier. > > My question is why two objects? It seems that there should be one object > that has this functionality. Is there a design reason behind this? Or is > it just because of historical accident? They seem to have overlapping > purposes. I couldn''t determine the reason for myself so I figured I > would go to the source. > > Eric > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- DCRails.com || Making the Metrorail fun!
Nicholas Schlueter wrote:> This is just my opinion, but after looking at the code I would say > that Form.element has a lot more to do with the retrieving data > (serialize, getValue) and Field has a lot more to do with the state of > the field (clear, focus, select, etc).I thought about that also but Field has present() and clear() which both operate on the value of the field. For consistency it would seem that it would be best to merge the objects and then for backwards compatibility alias all the methods under the other object. So: var Form.Element = { clear: function() { .... .. . }; var Field = Object.extend({}, Form.Element); That way a developer could use either object (although one would probably become more dominate). I would be interested to hear what others think. Eric