There seem to be two parts to this question: decomposition of the class hierarchy and implementation of the search algorithm.
In the Java world, there are two possible solutions to the decomposition problem :
- Local-oriented object-oriented decomposition, and
- Decomposition of type checking using
instanceof and type casting .
Functional languages ββ(including Scala) offer pattern matching, which is actually the best approach to implement validation type decomposition.
Due to the fact that it is necessary to work with a data structure (tree), where elements (nodes) can be of different types, the character of decomposition is definitely not local. Thus, the second approach is really the only option.
The search itself can be implemented using, for example, a binary search tree algorithm. Such a tree will need to be built from your data, where the decision on the location of a particular node should depend on the actual search criteria. Basically, this means that you need to have as many trees as there are different search criteria, which is essentially a way to build indexes. Database engines use more complex structures than a binary search tree. For example, red-black trees , but the idea is very similar.
By the way, the binary search tree will be homogeneous. For example, if the search refers to Employee in the Department , then the search tree will consist only of nodes associated with instances of Employee . This fixes the decomposition problem.
source share