This is more of a general question, but I don’t know if the space differs for different programming languages, so I tagged it with actionscript-3. I’ve had a lot of instances where I need a vector of usually 1 element, but maybe more some times. For example, how much more memory would I save if I use an int versus a vector of 1 int? Let’s say that I have a function that does something to all numbers in a vector. The input is usually going to be a single int, but some times I might need more. The size of the vector is also fixed, so I have no chance of a 1 element vector turning into a 2 element one.
Now I could do 2 things:
1) I could only use Vectors and have one function that takes in a vector, or
2) I could define 1 function that takes in a single int and another function that does the same thing but takes in a Vector of int’s.
Or maybe I could have it take in any type of argument, check the type of input and then cast it to an integer or vector? Basically, should I make 2 functions that caters to both cases or just 1 that only uses a vector?
OK took out the old example since it didn’t really apply.
If the size of the vector is not specified ahead of time, the size increases when the vector runs out of space. Each time the size of the vector increases, a new block of memory is allocated. So by not predefining the size of your vector, the memory footprint is just what’s needed to store one int.
So making one class is not a bad idea based on that alone. But now you need to look at the OOP of it all. So if most of your locks have one key, you really don’t what to have to access lock.keys[0] most of the time especially to even know you need to do that, you still need some indicator that it only needs and needs and has one key. lock.lockType or lock.requiredNumKeys or both. Since all of this logic and properties are specific to the rare times you need multiple keys, I say…
Build 2 classes.
EDIT:
One thing I thought I would mention is in using two classes you will probably at some point want an Array or Collection of locks. Make both classes implement and interface like IKeyedLock which defines a function addKey() and maybe a get isLocked() this way you can have a list will all IKeyedLocks, but the SingleKeyLock and MultiKeyLock classes determine differently if they are still locked or not and how to add a key (or keys)