salik saleem
salik saleem

Reputation: 847

What is the "General Hierarchy Pattern" in software engineering?

I am trying to understand the "General Hierarchy Pattern" but despite my efforts it remains unclear:

Upvotes: 0

Views: 2528

Answers (1)

Christophe
Christophe

Reputation: 73376

Where does this pattern come from?

This question raised my attention, since the name of the pattern doesn't ring a bell but the elements provided in the comments strongly suggested some variant of the well-known composite pattern. Some quick research suggests that this pattern is not widely known under that name. Only a couple of books seem to describe it:

I could not find any academic article refering to this pattern, at least under that name.

What is the general hierarchy pattern?

The better-known composite pattern describes a general hierarchical structure, in which a component can be made of a hierarchical aggregation of nodes specializing the component, some of them being leaf-nodes. This is a very general design pattern that covers many forms of hierarchical structures.

However, the composite is itself a specialization of the more general "general hierarchy pattern". According to T.Lethbridge & R.Laganiere:

  • an abstract Node defines the features and exposes the interface that is common to each node in the hierarchy. Each node can have a "superior";
  • there are at least two specializations of the general node, SuperiorNode and NonSuperiorNode depending on whether they must or not have a subordinate (i.e. be the superior of another node).
  • the relation between nodes may be any kind of association (i.e. not only aggregation as in the composite), with a multiplicity of optional-to-many (as in composite) or many-to-many

In UML, this would look like:

enter image description here

Personally, I am a little bit perplex with the many-to-many superior. Taking the example of managers and employees, this would look like a matrix, and a matrix is not really a hierarchy anymore. The authors mention that it's a lattice, but without argumenting about the relevance for hierarchies.

Remaining questions about this pattern

It is used for representing any kind of hierarchic structure. For example:

  • The manager/employee hierarchy, where a manager can have responsibility over a set of employees, some of these employees being themselves managers with responsibilities on a group of employees.

  • The department/employee hierarchy could be modelled using a composite, because a department is made of sub-departments, which are in the end composed of people.

The main benefit of this pattern is that the abstract Node exposes an interface that can be used for all nodes. This facilitates the design of algorithms that can navigate seamlessly through a hierarchy, wihtout having to care for specific details on each different hierarchical level.

Upvotes: 2

Related Questions