Background:
Information System of a Maufacture Industry. The Industry build components which comprises of sub-components, while sub-components comprises of sub-sub-components...
Strategy 1: Composite Pattern
In Bussiness Logic layer, components are organized as Composite Pattern.
And in DB, all components details are stored in one table.
Each component record has an "ID" and a "PID" field which indicates the ID of its parent component.
Strategy 2: Internal Code
In DB, each component record has a field "IID" which means Internal ID.
for example: for 3-layer hierarchy
"010000" for the first node of the first layer;
"010100" for the first node of the second layer, its parent id is "010000";
"010200" for the second node of the second layer, its parent id is "010000";
"010101" for the first node of the third layer, its parent id is "010100";
My personal idea is that Composite Pattern strategy is easy to extend and more professional.
While it seems hard to handle if cycle exists in the hierarchy.
Any ideas about it?
-
Which strategy should I choose for this Case? (1 messages)
- Posted by: mo cheng
- Posted on: April 27 2004 03:14 EDT
Threaded Messages (1)
- Which strategy should I choose for this Case? by Paul Strack on April 27 2004 10:56 EDT
-
Which strategy should I choose for this Case?[ Go to top ]
- Posted by: Paul Strack
- Posted on: April 27 2004 10:56 EDT
- in response to mo cheng
Strategy 2 is a horrible database design. Strategy 1 is much better. It allows tree of arbitrary depths, cycles etc. Also, for your likeliest queries (e.g. get all children of this node), Stategy 1 will execute faster.