From 692ad415024ed5fa45077dfe9210dff59e678ee9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 11 Feb 2026 09:19:18 +0100 Subject: [PATCH] Use implements instead of extends --- TODO.md | 2 +- lib/formula_models.dart | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index f67a06e..e8b971b 100644 --- a/TODO.md +++ b/TODO.md @@ -18,7 +18,7 @@ - [X] Create Formula.toStringLiteral. It is the reverse of Formula.fromSet( Formula.fromArrayStringLiteral(string)[0] ) - [X] Create UnitSpec.toStringLiteral, like Formula.toStringLiteral - [X] Make Formula and UnitSpec subclasses of FormulaElement. Change return type of functions that return Object to FormulaElement if necessary. -- [ ] Define toStringLiteral in FormulaElement. +- [X] Define toStringLiteral in FormulaElement. - Database file location: - [ ] In linux, the sqlite database file will be located following rules at https://specifications.freedesktop.org/basedir/latest/ - [ ] In Windows, the sqlite database file will be in %appdata%/Roaming diff --git a/lib/formula_models.dart b/lib/formula_models.dart index ede7ca5..af1c692 100644 --- a/lib/formula_models.dart +++ b/lib/formula_models.dart @@ -67,9 +67,13 @@ List parseCorpusElements(String arrayStringLiteral) { typedef Number = double; /// Abstract base class for formula elements -abstract class FormulaElement {} +abstract class FormulaElement { + /// Creates a string literal representation of the FormulaElement that can be parsed + /// by the D4RT parser to recreate the same FormulaElement object. + String toStringLiteral(); +} -class UnitSpec extends FormulaElement { +class UnitSpec implements FormulaElement { final String name; final String baseUnit; final String symbol; @@ -136,8 +140,7 @@ class UnitSpec extends FormulaElement { return units.toList(growable: false); } - /// Creates a string literal representation of the UnitSpec that can be parsed - /// by the D4RT parser to recreate the same UnitSpec object. + @override String toStringLiteral() { final buffer = StringBuffer('{'); buffer.write('"name": "$name", "symbol": "$symbol"'); @@ -194,8 +197,7 @@ class VariableSpec { @override int get hashCode => Object.hash(unit, name, values != null ? const DeepCollectionEquality().hash(values!) : 0); - /// Creates a string literal representation of the VariableSpec that can be parsed - /// by the D4RT parser. + @override String toStringLiteral() { final buffer = StringBuffer('{'); buffer.write('"name": "$name"'); @@ -219,7 +221,7 @@ class VariableSpec { } } -class Formula extends FormulaElement { +class Formula implements FormulaElement { final String name; final String? description; final List input;