From f3beef8ce2f538783889c55d685fa30a471983b7 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 24 May 2026 14:01:31 +0300 Subject: refactor(repl): introduce RPNCalculator interface to fix DIP violation (task rj) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- internal/repl/repl.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'internal/repl/repl.go') 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 -- cgit v1.2.3