I was looking an old project and i saw one code there that I am explaning here:
The code was loading some records(domain objects) from database then iterate over it then for each iteration they are getting on object through which they are loading again a list. They are doing this activity by putting nested for-loops in the code.
ParentList = getFromDatabse;
for(....){ // over ParentList
SubChild1List = fromParentObejct;
for(... ) { // over SubChild1List
subChild2List = fromSubChild1Objectl
.. so on
The code is having 7 nested loops.
My question is to suggest me some good design-pattern to avoid such a messy code.
Use the visitor pattern and recursion. It’s hard to say more since your code does not tell much.