You could use an array to replace all your fields.
Const CARCOLOR:Int = 1
Const CARTYPE:Int = 2
Const CARMASS:Int = 3
Type TCar
Const NumberOfStringFields = 5
Field StringArray$[]
Method New()
StringArray = StringArray[..NumberOfStringFields]
End Method
Method Clone:TCar()
temp:TCar = New TCar
For i = 0 Until NumberOfStringFields
temp.StringArray[i] = StringArray[i]
Next
Return temp
End Method
End Type
car1:TCar = New TCar
car1.StringArray[CARCOLOR] = "red"
car1.StringArray[CARTYPE] = "Viper"
car1.StringArray[CARMASS] = "1500"
car2:TCar = car1.Clone()
car2.StringArray[CARCOLOR] = "white"
car2.StringArray[CARMASS] = "1250"
For i = 0 Until TCar.NumberOfStringFields
Print car1.StringArray[i]
Next
Print
For i = 0 Until TCar.NumberOfStringFields
Print car2.StringArray[i]
Next
Now, if you want to increase the number of fields, you only have to adjust the value of the Const-field "NumberOfStringFields".
The Clone-method also uses this new value directly, so cloning an existing object isn't a big problem.
The use of constants is only there so you can use a name for the index, rather than remembering which index stores a specific value.
Of course, for integers, you can have a separate array that only uses integers.
You would have to adjust the Clone method and the New method to process these separate arrays too.
For adding new fields, just:
- adjust the NumberOfStringFields value
- add Constants at the top of your code, so you can access the indexes of the array by a name