summaryrefslogtreecommitdiff
path: root/internal/repl/repl.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-24 14:01:31 +0300
committerPaul Buetow <paul@buetow.org>2026-05-24 14:01:31 +0300
commitf3beef8ce2f538783889c55d685fa30a471983b7 (patch)
tree4f1df576d4d085933cea0cb8e9956f30b8492e6d /internal/repl/repl.go
parent4c64d3869230b2aa22f7f2635e0851e355b24ca4 (diff)
refactor(repl): introduce RPNCalculator interface to fix DIP violation (task rj)
Handlers accessed repl.rpnState.rpnCalc — three levels of concrete types violating DIP and Law of Demeter. Define an RPNCalculator interface capturing only the methods handlers actually need, and expose it via REPL.RpnCalculator() so handlers depend on the interface, not the concrete chain of *rpn.RPN.
Diffstat (limited to 'internal/repl/repl.go')
-rw-r--r--internal/repl/repl.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/internal/repl/repl.go b/internal/repl/repl.go
index 98ff23e..2ecd9ea 100644
--- a/internal/repl/repl.go
+++ b/internal/repl/repl.go
@@ -87,6 +87,16 @@ type REPL struct {
logWriter io.WriteCloser
}
+// RpnCalculator returns the RPN calculator behind this REPL as an interface.
+// This lets handlers depend on the RPNCalculator interface (DIP) rather than
+// reaching through repl.rpnState.rpnCalc into concrete types.
+func (r *REPL) RpnCalculator() RPNCalculator {
+ if r.rpnState == nil {
+ return nil
+ }
+ return r.rpnState.rpnCalc
+}
+
// ReadlinePrompt provides an interactive prompt using chzyer/readline.
// It supports:
// - Ctrl+R for reverse history search