Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COHow often is it really advantageous to the caller to have a *compiler-enforced* guarantee that `new Fizzle` will return a new instance of `Fizzle` rather than a recycled instance of `Fizzle`, or an instance of some derived class, or `null`? I suspect that the main reason people use public constructors is simply that if construction of a `Fizzle` requires one parameter of type `string`, it's more convenient to declare a `public` constructor that takes one `string` than to define a `protected` constructor along with a `public` method that calls it.
      singulars
    2. CO@supercat the advantage is that you make it more intuitive for the developer and easier to maintain. If you declare a new `FairlyComplicatedType` then modify it, and then realise that your other instance of `FairlyComplicatedType` was also modified, it'd be confusing for the poor developer who just wants a new instance of that type. What should they call to get a new instance if `new` actually gets them an old instance? Perhaps we could create a factory method called `GetNewFairlyComplicatedTypeForRealThisTimeHonest`.
      singulars
    3. COJust as a factory method can either be broken or work correctly, so too with a constructor. The compiler can guarantee that the return of the constructor will be a non-aliased reference to an object of a particular exact type, but it can't guarantee that the object will be usable in any way. The only one of the above not guaranteed by a *non-broken* mutable-class factory which isn't called something like `TryCreateFoo()` would be the *exact* type of the object; a non-broken factory could return an object of another type iff that other type was 100% compatible with the declared type.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload