I've managed to program the following THWorkingMemory class, into a antipattern, the God Object. I planned it to be a fairly small class with around 20 methods, but now it's packed with queue handlers, timers, threads, callbacks, powershell queue callbacks, event handlers, lock handlers and about 50+ methods, i.e. the lot. The class has grown far too big to be maintainable, and I need to split into smaller classes. But how to do it?
The THWorkingMemory class fundamentally defines around 8 main code blocks, which would suggest 8 seperate classes, but all the methods which write to the TreeDictionary use the ReaderWriterLockerWrapper.
Here is the code.
interface IWorkingMemory
{
protected CMemory CBase;
protected CMemory CCM { get { .. }
public abtract event ..
public abstract void ExecuteAction(Guid ExecutionGuid, string jim ... ...);
..
..20+ methods, events
}
internal sealed class CMemory
{
public CMemory()
{
CBase=new TreeDictionary<Guid, ExecutionState>(new comparer);
} ..
}
public sealed class ExecutionState
{ // 20+ methods. that act against the treedictionary node }
internal sealed class THWorkingMemory:IWorkingMemory
{
lockStrategy = new ReaderWriterLockerWrapper();
public void ExecuteAction(Guid ExecutionGuid, string jim ... ...)
{
lockStrategy.AcquireWriteLock()
CCM[ExecutionGuid].CreateExecutionState(jim);
lockStrategy.ReleaseWriteLock()
}
2000 lines+ of methods, timers, threading, events, callbacks,
queues processing. powershell script callbacks from ExecutionState, etc.
}
private ReaderWriterLockerWrapper
{
public void AcquireWriteLock(int timeout) {}\n
public void ReleaseWriteLock() {}
}
I had a look at the questions regarding partial classes, but they don't get a good writeup. It would make sense here, as the ReaderWriterLockerWrapper is used by most methods in the THWorkingMemory class.
What's the best way of splitting the THWorkingMemory, so it preserves the veracity of the lock class, i.e. ensures that writes into the tree dictionary don't conflict, that is writes are locked. I also looked at nested classes, which would work as a solution, but not be able to use the locker in the same manner it is now.
Any ideas?