How to handle input of one type and output of another
algorithm, design-patterns, java
Solution
Do it in the constructor. That is only going to be called once. If you do it in the getter you'll have to do the split many times.
Problem
I have an extremeley small and simple class but it is giving me some problems in how best to deal with it. It has a constructor and a single get method. The purpose is to store an array of values and return them when asked via the get method. Additionally, the array of values might be passed as a comma separate string to the constructor. And this is where i cant decide how to handle things. - Should the constructor split the string and trim element before storing the property - Should the constructor simply store the property and each time the getter is called, the property should be split - Should the getter check the property and if its a string, split it and then store the value for future calls to getter not have to ...