c# - Initialize child class from base definition -
Apologies if this is a commonly asked question, but I have a lot of googling for a while to spend the answer and no definitive answer could get . I have an abstract class in which fields are included (definitions of) Other abstract classes are then used for the solid implementation of properties. However, when I want to start implementing that intangible class, then I want to populate those areas with the special implementation of the field. . In fact, even that seems confusing here so here Example Although it technically complies with and works, there is a problem. Use _logWriter while I could use only declare methods and properties in the abstract class LogWriter am, but is not implemented in addition to the additional child (Sinklograitr). While technical it makes sense I wonder if there is any way to approach the same, but all the extra stuff available available in SyncLogWriter is available?
// My main abstract class public abstract class Log {public virtual bool AppendLog {set {_logWriter .ppend = value; }} Internal logger _logWriter; // LogWriter is another abstract class public abstract zero zero addEntry (string input); } // abstract class implementation of the public square SyncLog: Log {public SyncLog {// I // Want to start LogWriter abstract class parents with the actual implementation SyncLogWriter: LogWriter _logWriter = new SyncLogWriter (); } Public override zero AddEntry (string input) {content.AddEntry (input); _logWriter.Write ("hello"); }}
An additional member _syncLogWriter
got square inherited SyncLog < / Code>. Apart from this, it is even better to get started using your
_logWriter
builder for the base class and make it private.
// My main essence log for the public abstract category {protected log (logword log log) • {_logWriter = logWriter; } Public Virtual Bull AppendLog {Set {_logWriter.Append = value; }} Private logger_log author; // LogWriter is another abstract class public abstract zero zero addEntry (string input); } // abstract class implementation of the public square SyncLog: Log {private SyncLogWriter _syncLogWriter public SyncLog (): this (new SyncLogWriter ()) {} private SyncLog (SyncLogWriter logWriter): base (logWriter) {_syncLogWriter = logWriter; } Public override zero AddEntry (string input) {content.AddEntry (input); _syncLogWriter.Write ("hello"); }}
Comments
Post a Comment