So here is the code:
public interface IObserver<T> where T : StackEventData<T>
{
void HandleEvent(StackEventData<T> eventData);
}
public class Observer<T> : IObserver<T> where T : StackEventData<T>, new()
{
public StringBuilder Log = new StringBuilder();
public void HandleEvent(StackEventData<T> eventData)
{
Log.Append(eventData);
}
}
public class StackOperationsLogger
{
private readonly Observer<T> observer = new Observer<T>();
}
I need to initialize Observer observer in StackOperationsLogger without making StackOperationsLogger generic. Any suggestions?
Observer<T>mean to you if StackOperationsLogger isn't generic? How would you use it?Twith the appropriate type, which seems difficult because you need a type that is a StackEventData of the same type... what is StackEventData<T> and why is it generic?System.IObserver<T>just for reference because your version is so different. Personally I've been studying the pattern for a couple years now and it is really useful.