How to design a "tree struct" model?

Hi,
I’m developing a “File Manage” feature.
This feature maintain many files like the Windows’s Explorer.
The concept include Folder and File, Folder can include many File, Folder can include Folder also, File is a leaf node,can’t include child.
How to design model for this feature?Should i use ASSOCIATE or COMPOSITE?Is there a sample for this struct?
Thanks.

Hello,

according to the basic idea, the ‘Association’ relation should be used when two related objects have their own lifecycle and can exist independently. In case of the ‘Composition’ relation, the child object will always have the same parent.

In typical filesystems, all files and folders have a parent, but this parent can be changed to another. Also, the root folder does not have a parent at all.

So the ‘Association’ relation is what should be used in your model. There is no any sample for such structure, but I can prepare one if you want.

Best regards,
Daniil.

1 Like

Hi,
Thanks!
Now i gain a deeper understanding about ‘Association’ and ‘Composition’.
I design a entity model like this:


Entity      |            Attributes                      |  ParentClass 
----------------------------------------------------------- 
BaseFile  |           name、folder                 | SYS$StandardEntity 
----------------------------------------------------------- 
Folder     |           children                          | xx$BaseFile 
----------------------------------------------------------- 
File         | additional  attribute for a 'File' | xx$BaseFile               

Folder.children Association with BaseFile ,the Association is One to Many.
BaseFile.folder Association with Folder, the Association is Many to One.
A folder can include many File or Folder. File and Folder has a folder (Folder type) attribute represent it’s Parent,the folder attribute may be null.
Is it a rational design?
Another problem is hwo to utilize the model with screen?
My imagine is a screen have two part:The left part is a Tree,the right part is a grid. The tree only show “Folder” data, When select a tree node,show all the child Folder or File in Right Grid. How should i do?

Yes, your design is ok.
What components should you use on your screen depends only on your own needs. Your variant is good enough - it is a basic realization of a file manager.
In addition to Tree and Grid components, you can use the FileUploadField component and use second part of your screen as a drop zone to have an ability to upload files from your computer by drag-and-drop ability.
Another option is to build a list view using DataGrid or Table components. It will allow you to add filtering via the Filter component.
Take a look at the list of visual components (docs). Probably, something will be useful for you.
Best Regards,
Daniil.

Thanks very much!