开发者

Help understanding the Reader/Writer pattern in .NET

Here's the documentation for the method XContainer.CreateWriter:

Creates an XmlWriter that can be used to add nodes to the XContainer.

I parse the text with my mind, I get:

  • A method implemented by the class XContainer
  • Returns an instance of the class XmlWriter
  • The purpose is to add nodes to the instance of the XContainer on which the method is called.

How开发者_Go百科ever, I see XmlWriter, and I think of "writing XML". But that contradicts the above purpose in my mind, which is to add nodes. If I'm going to be adding nodes, wouldn't a "reader" be the thing I use to do so?

I'm not claiming anything is wrong other than my confusion here. I'd like assistance in grasping the apropriate metaphor so I can keep this straight in the future.

How is the naming convention used in Readers/Writers related to thier functionality in .NET framework classes?


Reading involves no modification to the data structure. That's why you have read-only access which means that no modification can be made.

In your case you will be modifying the data structure (adding nodes) therefore you're not only reading but also writing (those new nodes).

PS. Your second bullet point is not entirely true. The method can return the class that derives from XmlWriter, too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜