Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6532239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:58:35+00:00 2026-05-25T09:58:35+00:00

As a javaland programmer I’m used to Factory Methods and Multiple Constructors. My main

  • 0

As a “javaland” programmer I’m used to Factory Methods and Multiple Constructors.
My main uses for factory patterns are to delay decisions until runtime, perform some kind of side effect or restriction during the instantiation or hide the concrete type.
As I dig into C# I see more and more APIs that mix multiple constructor and static Create methods.

E.g., XmlReader and XmlTextReader. XmlWriter and XmlTextWriter.

My questions are:

  1. Is there something special with Create methods or it is just a convention (like java: getInstance)?
  2. What are the good practices in C# regarding factory methods vs constructors? Why, for example, there are several Create methods that accepts XmlWriterSettings arguments in XmlWriter and no constructor in XmlTextWriter with the same purpose? And, in the other hand, why only constructors accepts Encoding arguments?
  3. I guess the main question is, in idiomatic C#, when is it recommended to expose factory methods and when should public constructors be exposed?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:58:35+00:00Added an answer on May 25, 2026 at 9:58 am

    1) The only difference I know of is that generic type inference is supported for methods but not for constructors. Therefore, you can write:

    var str = "foo";
    var num = 42;
    var tuple = Tuple.Create(str, num);
    

    While if you wanted to use a constructor (unfortunately Tuple does not have a public constructor, so the example won’t compile) you would have to write:

    var tuple = new Tuple<string, int>(str, num);
    

    Of course this only applies to constructors of generic types, so it’s not exactly a mainstream difference.

    2) I suspect that was kind of a “random” (if “random” sounds harsh, then let’s say “not made with best practices foremost in mind”) decision, but I don’t have any data to back this up.

    3) Factory methods are also the only way you can return an object cast as one of its ancestor types. Sometimes this is not only desirable but also necessary because the user of your type might not know what type they are supposed to construct. For example, consider a factory method that returns a Stream which might be either a RedStream or a BlueStream, depending on some input parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am brand new to Visual C#. (I come from javaland) I used the
I am recently back in Javaland from Ruby and Activerecord and was wondering if
I guess I just got used to saying things like: x++ in PHP and
I'm looking for a quick and dirty way in Java to flash up a
I've clearly been stuck in Java land for too long... Is it possible to
I've been off in Java land for about a month or so and now,
Trying to understand resources in java-land. I believe the following is true: Resources loaded
I am trying to recreate SwiXML examples in JRuby. But the objects created in
I have a regex that contains a character class followed by TWO cadinality characters
I'm trying to write a script that is executed with the jruby-complete.jar like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.