Create a method to convert types from string to that type #15
Open
opened 6 years ago by SimonG96
·
0 comments
Loading…
Reference in new issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Is there a need for a method that converts user types from string to that specific type?
If so, create an interface
IGBaseObjectthat provides a methodFromString()like this:Another possibility would be to implement a static method
FromString()that creates a new instance in every class that needs this:Third we could add a constructor and/or a factory with only a
stringas parameter and create a new instance that way:Disadvantages of the last two solutions would be that a user would have to remember to implement these for every type, and you wouldn't be able to call it at a place where you don't have an instance of the actual type.