From 1f2c2460333ef0b9a214c9a1dea2eba16649df6f Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Thu, 25 Jul 2024 12:25:41 +0200 Subject: [PATCH] interface Calculator --- Calcium/Enums.swift | 12 +----------- .../com/romanpodymov/kmm/shared/CalciumEnums.kt | 10 +++++++++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Calcium/Enums.swift b/Calcium/Enums.swift index 033eff0..addff5d 100644 --- a/Calcium/Enums.swift +++ b/Calcium/Enums.swift @@ -9,11 +9,7 @@ import BigNumber import CalciumCommon -protocol Calculator { - func calculateValue(lhs: String, rhs: String, operation: CalciumCommon.Operation) -> String -} - -struct NativeCalculator: Calculator { +class NativeCalculator: CalciumCommon.Calculator { func calculateValue(lhs: String, rhs: String, operation: CalciumCommon.Operation) -> String { .init( operation.calculateValue( @@ -24,12 +20,6 @@ struct NativeCalculator: Calculator { } } -extension KMMCalculator: Calculator { - func calculateValue(lhs: String, rhs: String, operation: Operation) -> String { - operation.calculateValueKMM(lhs: lhs, rhs: rhs).toPlainString() - } -} - extension CalciumCommon.Digit: CalciumCommon.CalculatorButtonRepresentable { public var displayingValue: String { String(value) diff --git a/CalciumCommon/src/commonMain/kotlin/com/romanpodymov/kmm/shared/CalciumEnums.kt b/CalciumCommon/src/commonMain/kotlin/com/romanpodymov/kmm/shared/CalciumEnums.kt index dd4c5ce..809aabc 100644 --- a/CalciumCommon/src/commonMain/kotlin/com/romanpodymov/kmm/shared/CalciumEnums.kt +++ b/CalciumCommon/src/commonMain/kotlin/com/romanpodymov/kmm/shared/CalciumEnums.kt @@ -66,4 +66,12 @@ sealed class CalculatorButton { class SomeOperation(val operation: Operation) : CalculatorButton() } -class KMMCalculator {} \ No newline at end of file +interface Calculator { + fun calculateValue(lhs: String, rhs: String, operation: Operation): String +} + +class KMMCalculator: Calculator { + override fun calculateValue(lhs: String, rhs: String, operation: Operation): String { + return operation.calculateValueKMM(lhs, rhs).toPlainString() + } +} \ No newline at end of file