summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-20 22:29:28 +0200
committerPaul Buetow <paul@buetow.org>2026-03-20 22:29:28 +0200
commit015d238aa65d5b1ac087e13d3a07d262bc9790d1 (patch)
tree1c5d078e1c5b64c1f30794e5dfb5d30d17605d34
parent334bcac0302e8e2b58d3e86273791e887d3915ba (diff)
internal/rpn: define Operator interface and make RPN depend on it
- Added Operator interface in operations.go with all required methods - Updated RPN struct to use Operator interface instead of concrete *Operations type - This fixes the SOLID Dependency Inversion Principle violation
-rw-r--r--internal/rpn/operations.go30
-rw-r--r--internal/rpn/rpn.go4
2 files changed, 32 insertions, 2 deletions
diff --git a/internal/rpn/operations.go b/internal/rpn/operations.go
index 2f4b84c..1ebd78b 100644
--- a/internal/rpn/operations.go
+++ b/internal/rpn/operations.go
@@ -5,6 +5,36 @@ import (
"math"
)
+// Operator defines the interface for operator implementations and stack manipulation.
+// This allows RPN to depend on an abstraction instead of the concrete Operations type.
+type Operator interface {
+ // Arithmetic operators
+ Add(stack *Stack) error
+ Subtract(stack *Stack) error
+ Multiply(stack *Stack) error
+ Divide(stack *Stack) error
+ Power(stack *Stack) error
+ Modulo(stack *Stack) error
+
+ // Hyper operators
+ HyperAdd(stack *Stack) error
+ HyperSubtract(stack *Stack) error
+ HyperMultiply(stack *Stack) error
+ HyperDivide(stack *Stack) error
+ HyperPower(stack *Stack) error
+ HyperModulo(stack *Stack) error
+
+ // Stack manipulation operators
+ Dup(stack *Stack) error
+ Swap(stack *Stack) error
+ Pop(stack *Stack) error
+ Show(stack *Stack) (string, error)
+
+ // Variable operations
+ ListVariables() (string, error)
+ ClearVariables()
+}
+
// Operations provides operator implementations and stack manipulation.
type Operations struct {
vars VariableStore
diff --git a/internal/rpn/rpn.go b/internal/rpn/rpn.go
index 5c2b844..348da96 100644
--- a/internal/rpn/rpn.go
+++ b/internal/rpn/rpn.go
@@ -8,8 +8,8 @@ import (
// RPN represents the RPN parser and evaluator.
type RPN struct {
- vars VariableStore
- ops *Operations
+ vars VariableStore
+ ops Operator
maxStack int
currentStack *Stack
}