mardi 10 novembre 2015

c# Design pattern related to Repository

I have a repository class say call FileRepository() working in the C# managed layer. There is a method call LoadRecordFromFile() which access to the C++ unmanaged COM DLL to load a large amount of records, as shown :

LoadRecordFromFile()
{
     for (uint index = 1; index <= this.File.Count; index++)
     {
      // create new record object here
     }
}

The information in the record object will later used to generate AnalysisViewModel object. Thus, There is another for loop used to generate a collection of AnalysisViewModel objects before it can be used in the View for display.

The problem is that the second for loop is using vast amount of loading time. I am trying to optimise the loading time by replacing two for loop by using one for loop in the LoadRecordFromFile(). ie create both record object and AnalysisViewModel() object together in the for loop in LoadRecordFromFile() in FileRepository class. However It breaks the encapsulation of repository design pattern. Please would someone propose how to redesign the two classes (AnalysisVeiwModel and FileRepository)to achieve using only one for loop to reduce the file loading time ? Thank you

Aucun commentaire:

Enregistrer un commentaire