Complex objects hierarchy

Complex objects hierarchy

Old forum URL: forums.lhotka.net/forums/t/2642.aspx


SaguiItay posted on Friday, March 30, 2007

Hi there,

I'm currently in the process of reading the c# book, and I have a few question that will help me understand whether CSLA will suit my needs.

The software that I'm working on have a look-and-feel of a Windows Explorer - a treeview wit ha hierarchy of folders, and a listview that displays files and folders. The software itself allows the user to browse and manage the files structure. Obviously, I'll need Folder & File BusinessObjects. Each of these objects needs to have quite alot of metadata, so we're using a Property & a PropertySet objects, which will become BusinessObjects on their own.

My questions are these:
1. How do I handle the big hierarchy that might be created and handled?
2. Is there any way to prevent everything from sitting in the memory of the client? Obviously, the client doesn't need the list of files of a folder when he's not looking at that folder...

I'm pretty sure I'll have tons of more questions as I get into this a bit deeper.

 

Thanks in advance,
Itay Sagui

hurcane replied on Saturday, March 31, 2007

Not looking at a folder can have two states:
    1) Never looked at
    2) Looked at previously

I wouldn't worry too much about scenario #2. .NET garbage collection should clean up that memory automatically. In the first scenario, you probably want to avoid loading the entire structure up front. I would consider the following objects:

FileInfo
FolderInfo
Folder

Folder is an object that contains a list of FileInfo and FolderInfo objects. FolderInfo is a lightweight version of the Folder object. It wouldn't contain a child collection. You can put a function on the FolderInfo object to return a "full" Folder object that has the collection of its contents.

You'll probaby want a navigational function to retrieve the parent folder as well. This would be implemented in the Foder object.

You would then be loading folder contents one folder at a time, as needed by the user, and not wasting memory. You should avoid holding references to other Folder objects within any of these objects. That will prevent the garbage collector from destroying those objects.

How long will it take to load your folder contents? If that is a quick process, then you can simply keep reloading previously viewed folders as the user navigates to them. Otherwise, you might want to implement a cache of previously viewed folders. If you do that, be sure to implement a "timeout" mechanism for the cache, or else you will end up with the entire set of folders in memory if the user navigates through the entire structure.

Copyright (c) Marimer LLC