Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Move pre-/post-/infix output printing functionality to Visitor design pattern #41

Open
tommens opened this issue Feb 9, 2022 · 0 comments
Labels
refactoring Restructuring the code to increase its internal structural quality

Comments

@tommens
Copy link
Owner

tommens commented Feb 9, 2022

** Issue **
Currently the functionality of converting an expression to a string using prefix, postfix or infix notation is hardcoded as part of the Expression class hierarchy. More specifically, it is defined in the toString(Notation) method of the Operation class. This does not make much sense, since the way of outputing an expression in string format should be independent of how the expression is structured and represented internally.
A cleaner solution would be to use the Visitor design patterns, that is already present for evaluating expressions. A new visitor could be implemented for outputting arithmetic expressions as strings using different possible notations (prefix, postfix, infix traversal).
At the same time, the "counting methods" to count the numbers and operations and depth of an expression could also be moved out of the expression hierarchy in another visitor.

This refactoring will require to change some of the unit tests as well, since it will change the current way in which the code is structured.

** Classification **
suggested code refactoring

** Related issues **
This proposed refactoring is related to bug issue #39 that will, in principle, be resolved if the proposed refactoring is carried out correctly.

@tommens tommens added the refactoring Restructuring the code to increase its internal structural quality label Feb 9, 2022
AlixDeclerck referenced this issue in AlixDeclerck/calculator-cucumber Mar 8, 2022
…ator subclass that handle the (detailed) print and adapt Calculator class to use it.
yoest referenced this issue in yoest/calculator-cucumber Apr 22, 2023
UmonsVDA referenced this issue in UmonsVDA/calculator-cucumber Apr 27, 2023
UmonsVDA referenced this issue in UmonsVDA/calculator-cucumber Apr 28, 2023
Refactor notation #41 into master branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Restructuring the code to increase its internal structural quality
Projects
Development

No branches or pull requests

1 participant