Skip to content

First cut of replacement for the poorly regarded #queryCommand: "switch"#1201

Merged
blairmcg merged 3 commits into
masterfrom
blairmcg/querycommand1
Dec 16, 2023
Merged

First cut of replacement for the poorly regarded #queryCommand: "switch"#1201
blairmcg merged 3 commits into
masterfrom
blairmcg/querycommand1

Conversation

@blairmcg

Copy link
Copy Markdown
Contributor

The #queryCommand: method is one of the least satisfactory elements of the original MVP design, because it results in a large and often complex and difficult to maintain switch statement (albeit a switch on value, and not type). It also doesn't lend itself to extensibility, and consequently various ad-hoc approaches have been used to achieve that, e.g. registering additional handlers in the dev tool presenter hierarchy, and the use of ClosedCommandDescriptions (commands that have their own query block, and
which are invoked first, effectively shortcutting the normal chain-of-command route).

This PR adds a prototypical replacement mechanism using method annotations to associate a query function with a command. The annotation is placed in the command method and specifies the selector of the query function for that command. A single query method can be associated with multiple commands.

In order to test out the mechanism in practice, the #queryCommand of ClassSelector has been replaced. This is a relatively complex example, and so should cover many of the variations. A couple of extension cases have also been implemented with the new mechanism. It is, however, expected that other cases will be encountered as more #queryCommand: methods are replaced, and so the design may require refinement.

All uses of the existing extension mechanism that allowed for provision of extra old-style command query methods, e.g. the queryRefactoringCommand: methods added to PackageBrowserShell, etc, have also been replaced.

The #queryCommand: method is one of the least satisfactory elements of the
original MVP design, because it results in a large and often complex and
difficult to maintain switch statement (albeit a switch on value, and not
type). It also doesn't lend itself to extensibility, and consequently
various ad-hoc approaches have been used to achieve that, e.g. registering
additional handlers in the dev tool presenter hierarchy, and the use of
ClosedCommandDescriptions (commands that have their own query block, and
which are invoked first, effectively shortcutting the normal
chain-of-command route).

This commit adds a prototypical replacement mechanism using method
annotations to associate a query function with a command. The annotation
is placed in the command method and specifies the selector of the query
function for that command. A single query method can be associated with
multiple commands.

In order to test out the mechanism in practice, the #queryCommand of
ClassSelector has been replaced. This is a relatively complex example, and
so should cover many of the variations. A couple of extension cases have
also been implemented with the new mechanism. It is, however, expected that
other cases will be encountered as more #queryCommand: methods are replaced, and
so the design may require refinement.

All uses of the existing extension mechanism that allowed for provision of
extra old-style command query methods, e.g. the queryRefactoringCommand:
methods added to PackageBrowserShell, etc, have also been replaced.
@blairmcg blairmcg merged commit 6e0498f into master Dec 16, 2023
@blairmcg blairmcg deleted the blairmcg/querycommand1 branch December 16, 2023 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant