Jump to content
  • Advertisement
Sign in to follow this  
Daniel Miller

C#: private constructors

This topic is 4783 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Since there is no friend keyword, how do instances of classes like XmlNode (with I assume only a private constructor) get created? It doesn't have any static methods, either. This question is quite newb, and I know I am either missing something obvious or making a mistake in my assumptions about XmlNode.

Share this post


Link to post
Share on other sites
Advertisement
XmlNode is an abstract class. Abstract classes cannot be instantiated. Instead you derive from the class and instantiate that.

Share this post


Link to post
Share on other sites
Oh...

Do all of the Xml methods in System.Xml give the user abstract classes as a protection to other classes behind the scenes? I noticed that XmlElement is the same way as XmlNode. Why didn't they call them interfaces, then?

Thanks for replying. [smile]

Share this post


Link to post
Share on other sites
*thinks*

Why would there need to be code? If they pass the user an interface, the user could play around with it while not caring what it actually represented, right?

edit: One bonus for not using interfaces is that the user can't inherit.

Share this post


Link to post
Share on other sites
Because the XmlNode class implements some basic details that are common to all nodes, irregardless of the details of their inner workings.

Share this post


Link to post
Share on other sites
Because there is more flexibility in inheriting from XmlNode, since its designers figured that there are things that all subclasses of XmlNode would probably want to be able to do. If you used an interface, any class that implements XmlNode would need to override all of its methods.

EDIT: I was a little slow to post...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!