Sumitra Paul

Sumitra Paul

  • NA
  • 51
  • 32.9k

Architechture question (Code design)

Aug 29 2012 10:54 AM

Hi,
Let me paste a sample code first:
 

internal class MyMainClass : AbstractClass


private readonly IDictionary<IData, IDataContext> MyDataContext =

new Dictionary<IData, IDataContext>();



/// <summary>


///


/// </summary>

/// <param name="data"></param>

/// <param name="subscribe"></param>

protected override void AbstractClassEventA(IData data, bool subscribe)
{

if(subscribe)
{


if(data.ActiveData != null)
{
data.

ActiveData.OnDataRendered += OnDataRendered;
}


else
{
AddData(data);
}
}


else
{
RemoveData(data);
}
}


/// <summary>


///


/// </summary>


/// <param name="sender"></param>


/// <param name="param"></param>


private void OnDataRendered(object sender, EventArgs param)
{


// DataViews is a inherited property which gets feeded somewhere else


foreach (var data in DataViews)
{
AddData(data);
}
}


/// <summary>


///


/// </summary>


/// <param name="data"></param>


private void AddData(IData data)
{


if (!MyDataContext.ContainsKey(data))
{


var SomeContext = new DataViewContext(data);
MyDataContext[data] = SomeContext;
}
}


/// <summary>


///


/// </summary>


/// <param name="data"></param>


private void RemoveData(IData data)
{


if (MyDataContext.ContainsKey(data) && data.ActiveData != null)
{
MyDataContext.Remove(data);
}
}

{

 
A class has been created long back by some other guy and now slowly the class is becoming very complex.
We have lot of variables, dictionaries, inherited abstract class in that. Now I want to
saparate some of the functionalities to other class. I am not that strong in c#. So expecting some class design help for saparating codes.
I cannot send the exact code. hence modifying some of the code and sending it so that you can get some idea.
My first question;
I want to totally saparate the the logic of AddData() and RemoveData() to saparate file. But since it uses some variables which are
used in AddData() and RemoveData() method are used in many places.
 
How can I make the dictionary to be used in my main class as well as saparated helper class.
Can i use some interface to decople this scenario. Actualy I need some design solution.
Second question:
In OnDataRendered() event, there is a list DataViews, which comes from inherited abstract class. Can I write that event handler in some new helper class. Since OnDataRendered() event handler also calls AddData(), the idea is to saparate all codes that deals with AddData() and removeData() method.

Or if you can suggest some of your idea to design such classes wud be great.
Thanks a lot.

Answers (1)