Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create Instance Of Class Through Method Call Only?
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01464302
Message ID:
01464339
Views:
39
>>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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform