开发者

Any know the reason xmlReader/xmlWriter only provide Create method rather than constructors

开发者 https://www.devze.com 2023-02-01 11:20 出处:网络
Just interesting to know. Why the constructors are protected for those class开发者_如何学Ces.Because XmlReader/XmlWriter are abstract classes and it doesn\'t make much sense to have a public construct

Just interesting to know. Why the constructors are protected for those class开发者_如何学Ces.


Because XmlReader/XmlWriter are abstract classes and it doesn't make much sense to have a public constructor in an abstract class. This is a common factory pattern. You use the static Create method which will return a proper implementation based on the argument types in a way that is completely transparent to the developer.


There are specialized types of XMLReader classes like Dictionary Readers, TextReaders etc. that derive from the abstract XMLReader class. You can instantiate those.

0

精彩评论

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