Skip to content

Add support for external feature control #3

@mmnaseri

Description

@mmnaseri

Right now, controlling a feature requires extending the original class for the data structure which, while trivial, is tedious.

It would be far better if there was a facility for proxying data structures and setting feature-base expectations on the data structure so that we could arbitrarily secure any given data structure of choice for any given task.

One example would be:

final SearchTree<Integer, ? extends TreeNode<Integer>> tree;
tree = new BinarySearchTree<Integer, BinaryTreeNode<Integer>>();
final SearchTree<Integer, ? extends TreeNode<Integer>> securedTree;
securedTree = givenDataStructure(tree)
                            .observe(inOrderWalkYieldsSortedValues())
                            .observe(minimumIsOnTheLeftMostNode())
                            .observe(maximumIsOnTheRightMostNode())
                            .observe(nodeIsGreaterOrEqualToItsLeftChild())
                            .observe(nodeIsLessThanItsRightChild())
                            .observe(nodeIsGreaterOrEqualToItsLeftChild())
                            .secure();

At this point, if the tree is not honoring any of the features, we will see MonitorFailureExceptions. Features will be checked before and after the execution of each operation, ensuring that the data structure is always in a valid state.

(We could probably monitor the data structure upon creation, and then after each operation, and it would suffice).

This should be theoretically implementable if features can be observed from the outside, which is not always the case. In such cases, a strategy is probably required and I should probably think of a way to incorporate that into the DSL.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions