Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Create Instance Of Class Through Method Call Only?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01464302
Message ID:
01464339
Vues:
40
>>You don't need a Factory (at least for this bit):
public class SomeClass
>> {
>>     private SomeClass()
>>      {
>>      }
>>      public static SomeClass GetInstance()
>>      {
>>        return new SomeClass();
>>      }
>> }
>>
>>//To instantiate:
>>SomeClass sc = SomeClass.GetInstance();
>>// This won't compile:
>>SomeClass sc2 = new SomeClass();
>
>Then this defeats the whole purpose. I don't want the class to be created from outside my factory. I want to be able to set things
>on the instance before returning it to the caller.

Then I think your options are limited. Either
(a) Create a CTOR for the class with parameters that accept the values you want to set
or
(b) Make the class private and hide it behind an interface.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform