I'm having a hard time trying to implement a SOLID principle regarding conditions inside loops. For example I have a List of objects inside an object.
public class ClassTwo{
int id;
string name;
string quantity;
bool markasDelete;
}
public class SampleClass{
string name;
List<ClassTwo> listClassTwo;
///other initializations, props, method ,construct
void Process(List<ClassTwo> newListOfClassTwo){
foreach(ClassTwo c in newListOfClassTwo){
if(c.id == 0)
{
///do other things
listClassTwo.Add(c);
}
else if(c.id > 0 && !markasDelete)
{
///do update things
}
else
{
///do delete things
}
}
}
}
As you can see from above my "Process" method is doing too much. I tried to reduce the work segragating each condition to a specific method but im very unhappy with it. My code now looks something like this.
void Process(List<ClassTwo> newListOfClassTwo){
foreach(ClassTwo c in newListOfClassTwo){
AddMethod(c);
UpdateMethod(c);
RemoveMethod(c);
}
}
Can please someone help me on this?