1) - , - , - .
2) " " , - (!!!), , SomeObject "this"
, "", 2 - . "", ... .. ...
u , obj
u
public abstract class MyClass{
private SomeObject _obj ;
public SomeObject Obj {get { return _obj ?? (_obj = InitializeObj() );}}
protected abstract SomeObject InitializeObj();
}
public class MyRealClass:MyClass {
protected override SomeObject InitializeObj(){
return new VerySpecialSomeObject(this, other, another, 1, 2 , false, option: new Options());
}
}
For your example, such a solution provides a single "template" that wins - "polymorphism")) and receives an additional bonus - if "Obj" is not useful, it will never be created))))
source
share