-1

I'm trying to model a system where I have directories with files. A directory contains files as well as directories.

I found a good method to represent a tree in an SQL database (http://falsinsoft.blogspot.com/2013/01/tree-in-sql-database-nested-set-model.html) -- the article describes the method named "nested set" but I have problems on how to model it in UML (class diagram).

Jongware
  • 22,200
  • 8
  • 54
  • 100
user3260388
  • 313
  • 1
  • 4
  • 10

1 Answers1

2

Here is a class diagram that represents the situation:

enter image description here

Compositions are used to reflect the fact, that if a Directory is deleted, all its contents (subdirectories and siles) are automatically also deleted.

Aleks
  • 5,674
  • 1
  • 28
  • 54
  • thx for the response ,but in a nested set model I have to add lft and rgt values in a table ,the proposed diagram need complicated queries to handle (join and recursive procedures) that influence the performance ,so the nested set model avoid all that and allow the delete of all subelements by deleting the parent ,my problem is how to model the nested set model in UML – user3260388 May 11 '14 at 21:02
  • Class diagram, I proposed, is a logical respresentation of explained situation with Dirs and FIles. Nested set is an implementation algorithm, used to implement the DB model, which resolves the logical problem. So, you need a class diagram that describes Nested set itself? In that case, you just need a single class with 4 fields: category_id, name, lft and rgt. Note that this alone does not describe the algorithm, just the underlaying structure. – Aleks May 11 '14 at 21:50
  • In your case, category_id can be DIR or FILE. Be sure to add additional logic that ensured that DIR can store DIR or FILE, while FILE cannot have children. That might be placed in stored procedures or elsewhere. This example makes a nice lesson in abstraction in software development. The class diagram that I proposed is on more abstract, logical level. Another one (a single class for Nested set) is physical level class diagram that implements the defined logic, including an transformation to optimize performance. The 1st one is focused on the logic and rules, the 2nd one - on the performance. – Aleks May 12 '14 at 07:15