I'm trying to create a power supply unit simulation. In order to do so, I must use the following interface:
Ramping should be implemented concurrently, so that other interface methods (except loadRamp) are available at all times.
This is my solution:
I'm a bit worried with the following:
1) Is the design OK? Could it be more elegant?
2) Is there an elegant way of enabling methods only when the unit is turned on (and not using ifs)?
3) Is the startRamp method designed OK, or could this be done better?
4) Are exceptions in set method necessary or should I just ignore the method if the device is ramping or off or value < 0? What would you do?
If you have any other comments or tips/advices, I'd be very thankful.
I'd ramp to the new value if the unit is currently ramping.
You might want look into various ways of implementing state machines.
I'd name the interface something other than Methods, since methods are the only things that should be in an interface--name it something more descriptive.
I'm a little wary of the "isDoneRamping" variable; from a cursory inspection of the code it's not clear to me what its purpose is--what differentiates it from !isRamping?
I'd also be wary of non-synchronized access to shared variables--if there are multiple threads accessing the same value there's always the possibility of someone walking over someone else's value. Depends on usage, obviously; just something to be aware of.