Why do we use Document object to create Element ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Why do we use Document object to create Element ?

叶现一
I have a question about create Element , TextNode or anything else like that in DOM. 
 
Why do we use Document object to create Element ? 
For Example: TextNode el = document.createTextNode("name").And then add el to one node.
 
Why don't we design a class like TextNode ?
And then instantiate it directly like  TextNode el = new TextNode().
Finally,use a node to add it,like node.appendChild(el).
 
 
I think that we use  Document object to create Element is unnecessary and is not fit to our thinking.
 
 
Do you have any suggestions about that ?
If you have ,Please send e-mail to [hidden email]
 
Thanks very much!


使用新一代 Windows Live Messenger 轻松交流和共享! 立即体验!
Reply | Threaded
Open this post in threaded view
|

Re: Why do we use Document object to create Element ?

joao.eiras (Bugzilla)
Document.createFoo makes use of the AbstractFactory pattern
http://en.wikipedia.org/wiki/Abstract_factory_pattern
You can read that article to have a good notion of why it's used in the DOM.



2008/4/22, 叶现一 <[hidden email]>:

>
> I have a question about create Element , TextNode or anything else like that
> in DOM.
>
>  Why do we use Document object to create Element ?
>  For Example: TextNode el =
> document.createTextNode("name").And then add el to one
> node.
>
>  Why don't we design a class like TextNode ?
>  And then instantiate it directly like  TextNode el = new TextNode().
>  Finally,use a node to add it,like node.appendChild(el).
>
>
>  I think that we use  Document object to create Element is unnecessary and
> is not fit to our thinking.
>
>
>  Do you have any suggestions about that ?
>  If you have ,Please send e-mail to [hidden email]
>
>  Thanks very much!
>
> ________________________________
> 使用新一代 Windows Live Messenger 轻松交流和共享! 立即体验!