Используйте Factory.
public class MyClass
{
private MyClass(int code){...}
public static MyClass CreateInstance(int code)
{
if (exist(code))
return new MyClass(code);
else
return null;
}
}
И создавайте свой объект так:
MyClass obj = MyClass.CreateInstance(150);
Any fool can write code that a computer can understand. Good programmers write code that humans can understand. ~Martin Fowler
Данное сообщение получено с сайта GotDotNet.RU
|