C++ design options - utility class, namespace, or other?

164 Views Asked by At

I am fresh to C++ from Java, and am currently in the process of figuring things out. I need some advice on something that I am implementing: it's for a simulation, and will essentially be a bunch of methods for translating between real time and simulation time (e.g. one of them will allow the user to specify a duration in simulation time, and the method will return the equivalent value in real time). There will also be a single field, which will be the length of a simulated day in real time seconds.

I can think of a few ways to implement this:

  1. Everything that uses these methods (which in turn use that variable) will descend from a single superclass. So, I could use a namespace to hold the methods and make the day length variable a field of the superclass.
  2. Make the day length variable global and use a namespace to hold the methods
  3. Have a utility class, as I probably would in Java (if I had to)

What do you think is the best option? If anyone can think of a better option than the ones listed here that would be welcome, too - I'd love to learn more about C++.

0

There are 0 best solutions below