NightOwl888 commented on code in PR #809: URL: https://github.com/apache/lucenenet/pull/809#discussion_r1161165931
########## src/Lucene.Net/Util/RollingBuffer.cs: ########## @@ -57,25 +58,17 @@ public abstract class RollingBuffer<T> // How many valid Position are held in the // array: private int count; - - protected RollingBuffer() - { - for (var idx = 0; idx < buffer.Length; idx++) - { - buffer[idx] = NewInstance(); // TODO GIVE ROLLING BUFFER A DELEGATE FOR NEW INSTANCE - } - } + private Func<T> factory; protected RollingBuffer(Func<T> factory) Review Comment: Great work. However after considering the change a little more, I thought of a way that this is more limited than it was in Lucene. Since a constructor injected `Func<T>` is static, we can no longer reference any state in the subclass. If we use an abstract factory instead, we can pass in the current instance as an argument. ```c# public interface IRollingBufferItemFactory<T> { T Create<TRollingBuffer>(TRollingBuffer rollingBuffer) where TRollingBuffer : RollingBuffer; } ``` And then call the factory like: ```c# for (int idx = 0; idx < buffer.Length; idx++) { buffer[idx] = rollingBufferItemFactory.Create(this); } ``` Then the factory can do things based on the state of the subclass. I think if it is declared like above, they won't need to do a cast to see the subclass members. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org