LemaireEmilien / calculator-cucumber-2024

This repository is used for teaching purposes at the University of Mons. It contains Java code for computing arithmetic expressions. The code uses design patterns and is accompanied with JavaDoc, unit tests and BDD scenarios. We have also paid particular attention to code quality.
0 stars 0 forks source link

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

Closed Super-JK closed 7 months ago

Super-JK commented 7 months ago

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 https://github.com/LemaireEmilien/calculator-cucumber-2024/issues/3 that will, in principle, be resolved if the proposed refactoring is carried out correctly.