A.3 Final Design
A.3.1 Data Structures
All of the data will be stored in several classes. This section will describe the data storage classes used for all of the unit data.
For each class, a summary of the reason for its existence will be followed by a table specifying any data stored within that class, and this will be followed by a description of any methods in the class.
Each instantiable (that is, non-abstract) class in this hierarchy will override the default equality operators, so that if two such objects contain the same information, they are considered to be equal. They will also contain a method, Get(), to return an identical copy of themselves. If a class contains any additional methods, these will be explained in this section.
OpenMath
This will be the (abstract) base class for the system, containing any functionality common to all the OpenMath classes. It also contains a variable which specifies the type of OpenMath object, for ease of identifying. This field is not strictly necessary, because it is possible to determine the class type by other means; however, in some cases it is easier to use this method rather than another.
APPENDIX A. SYSTEM DESIGNS: BACK-END 99
OpenMath
Datum Type
Type Enum: {OMA, OMI, OMS, OMV, OMF, Dimension, Definition, Unit, Operator}
This class contains no additional functionality. OpenMathCD
This will store all the data relating to a particular Content Dictionary, such as its name and version, and of course the definitions stored within it.
OpenMathCD:OpenMath
Datum Type
Name String
Date DateTime
ReviewDate DateTime Definitions OpenMathDefinitions Array Description String
Version Integer
Revision Integer
Status String
URL String
This class contains the following method:
• A Contains method, which determines whether the specified OpenMathSymbol is contained in this CD.
OpenMathCompoundType
This will be an abstract “sub-base” type for the OpenMath types which can contain others, such as OpenMathApplication and OpenMathDefinition.
OpenMathCompoundType:OpenMath
Datum Type
<No Members>
This class contains no additional functionality. OpenMathApplication
This is a class which will store the content of an OMA, and provide functionality to ac- cess/modify that content, for example to simplify fractions containing only numbers to an OpenMathNumericType.
OpenMathApplication:OpenMathCompoundType
Datum Type
Content OpenMath Array
One of the more complex classes, the OpenMathApplication class contains the following methods
APPENDIX A. SYSTEM DESIGNS: BACK-END 100 • An Add method, to add an item to the OMA.
• A Simplify method, which reduces the OMA to its simplest form
• An Unwrap method, which, when applied to an OMA with a single OMS, unravels the rest of the OMA to obtain a numeric value
• A ReverseApplyTo method, which reverses the effect of an OMA and applies it to a particular value
• A FindUnits method, to find all the units within the OMA
• Several Replace methods, which replace all occurrences of the first parameter with the second parameter
– OpenMathUnit to double, which creates an OpenMathFloat to store the double value
– OpenMathSymbol to OpenMath
– OpenMathVariable to OpenMathSymbol
• A GetAll method, which returns all of the objects of the specified type in the OMA • A ReplaceFirst method, which replaces the first occurrence of a particular symbol
with the given OpenMath object OpenMathDefinition
This is a superclass for OpenMathDimension and OpenMathUnit, but can also be instan- tiated itself. It contains all the data that can be obtained reading a particular definition in a CD. OpenMathDefinition:OpenMathCompoundType Datum Type Name String CD String Role String Description String FMP OpenMathApplication
This class contains no additional functionality. OpenMathUnit
This is a subclass of OpenMathDefinition for storing unit data. It contains additional flags and values that only units can have. The “None” value for unit type is available for units where the type could not be determined—at present there is no guaranteed method for determining this—but also means that more generic methods can be written, that will process units as well as other kinds of definition.
APPENDIX A. SYSTEM DESIGNS: BACK-END 101
OpenMathUnit:OpenMathDefinition
Datum Type
Dimension OpenMathDimension
Type Enum: {Metric, Imperial, Time, US, None}
Prefixable Boolean
Abbreviations String Array
This class contains several methods:
• An AllAbbreviations method, which returns a list of all the abbreviations
• A ConvertSymbolsToUnits method, which converts an array of OpenMathSymbol to an array of the corresponding OpenMathUnits
• A GetConstituentUnits method to return an array of the first level of units that make up this unit (i.e. non-recursive)
• An IsSimple method, which returns whether the unit is one of a basic type or not
OpenMathDimension
This is a subclass of OpenMathDefinition for storing dimension data. Although it contains no values, it is useful to be able to tell it apart from its superclass.
OpenMathDimension:OpenMathDefinition
Datum Type
<No Members>
This class contains no additional functionality. OpenMathSimpleType
This will be an abstract “sub-base” type for the simple OpenMath types such as OpenMath- Variable.
OpenMathSimpleType:OpenMath
Datum Type
<No Members>
This class contains no additional functionality OpenMathVariable
This stores the name of an OMV, which for the purposes of this system will only be used within the dimensions STS.
OpenMathVariable:OpenMathSimpleType
Datum Type
Name String
APPENDIX A. SYSTEM DESIGNS: BACK-END 102 OpenMathSymbol
An OMS is uniquely identified by a symbol name and an associated CD name, both of which this class will store.
OpenMathSymbol:OpenMathSimpleType
Datum Type
Name String
CD String
This class contains no additional functionality. OpenMathOperator
This is not really an OpenMath type; however, the designed implementation of the system is easier if the operators are a subclass of OpenMathSymbol. Due to the reasons put forward in section 4.4.2, we have decided to recognise this subset of operators, and replace the OMS with the corresponding OpenMathOperator for that object, so that when parsing the algebra, the system can easily tell which operator to use, and act accordingly.
OpenMathOperator:OpenMathSymbol
Datum Type
<No Members>
The operator objects will be singletons stored as static fields in this class, one for each of the recognised operators—eq from relation1, and times, divide, plus, minus and power from arith1. This class will also define the functionality of each operator, and contains the following methods:
• A GetOperator method, which returns the singleton OpenMathOperator correspond- ing to the supplied name and CD, or null.
• An IsKnownOperator method, which returns true if the supplied name and CD are that of a known operator, false otherwise
• An Operate method which performs the operation specified in an OMA, and returns the result, making use of the following methods:
– opDivide – opEquals – opMinus – opPlus – opPower – opTimes
APPENDIX A. SYSTEM DESIGNS: BACK-END 103 OpenMathNumericType
This is an abstract superclass for OpenMathInteger and OpenMathFloat added so that most parts of the system only need know that one or other is present, not specifically which one.
OpenMathNumericType:OpenMathSimpleType
Datum Type
Value Float
This class contains no additional functionality OpenMathInteger
This will store the value of the integer. Originally, the intention was that, as OpenMath integers are infinite precision, and programming language ones are not, it would use the highest precision integer type available, which in the case of C# is a long. However, to make implementation easier, its value is now stored in the double of OpenMathNumericType.
OpenMathInteger:OpenMathNumericType
Datum Type
<No Members>
This class contains no additional functionality. OpenMathFloat
This will store the value of the floating point number. Originally, the intention was that, as OpenMath floats are infinite precision, and programming language ones are not, it would use the highest precision floating point type available, which in the case of C# is a double. While this effectively still happens, the variable for storing the value is now located in OpenMathNumericType.
OpenMathFloat:OpenMathNumericType
Datum Type
<No Members>
This class contains no additional functionality.
A.3.2 Class Hierarchy
Based on these descriptions, we have come up with the class hierarchy shown in Figure A.3 on page 104.
APPENDIX A. SYSTEM DESIGNS: BA C K -E ND 104 OM OMType OMCD Name Definitions URL ReviewDate Status Date Version Revision Description OMCompoundType <No Members> OMA Content OMDefinition Name CD Role Description FMP OMUnit Dimension UnitType OMDimension <No Members> OMSimpleType <No Members> OMV Value OMS Name CD OMOperator <No Members> OMNumericType Value OMI <No Members> OMF <No Members> Figure A.3: The final Class Hierarchy for the system’s data storage.
APPENDIX A. SYSTEM DESIGNS: BACK-END 105