I have a method that needs to retrieve a type of size so for example I need a string to be returned that says “small”, “medium” or “large”.
So I call GetSize(int size). But I also need to know how I want to return the size, do I want to return “small” or do I want to return “s”. So the method grew to GetSize(int size, enum format).
Now I could do a switch case but it would be
switch (size)
{
case SMALL_SIZE:
switch(format)
case format::short
case format::long
}
So I would have to do a switch case inside every case for “size”. I could also break it down and call a method to get the format on every size case.
This seems like a lot of work, and I only have 3 cases of sizes here but imagine it was 10 cases for something else. Are my solutions best or is there a better way?
It appears that your method can be replaced by a simple two-dimensional array.