Login  Register

Dealing with multiple cases of a string while keeping code short and OOP friendly

Posted by kilon.alios on Mar 09, 2015; 4:32pm
URL: https://forum.world.st/Dealing-with-multiple-cases-of-a-string-while-keeping-code-short-and-OOP-friendly-tp4810731.html

So I am parsing strings that represent python types and other custom objects. An example would be

'<Vector (1.0 , 0.2 , 0.8) >' or '<Color (0.3 , 0.9 , 0.4 )>'
etc

But I dont want to use too many ifTrue , ifFalse and end up with a long method.

So I was thinking creating a OrderedCollection that would be 2D , first dimension is the regex that fits the type the second is the pharo object that corresponds to this type . Then I will have a common method for each of those pharo object to deal with the parsing.

But I was wondering how to use a class that I dont know its name until runtime. For example lets say i get a string

aPythonString := '< Bone [ "side bone" , IK = True , ( 1.0 , 0.1 , 0.2) ]>'

I would want in this case to send the message the EphBoneType parse : aPythonString. The problem is that I dont know the contents of the string until I receive it. So I want the name of the class to be composed according the string received .

Is this possible ? Is this a smart way ? How would you do it ?