Discussions

Web tier: servlets, JSP, Web frameworks: Which strategy should I choose for this Case?

  1. Which strategy should I choose for this Case? (1 messages)

    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?
  2. 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.