Let me start by saying I have very limited Android experience. That said, I did look into the SoundPool
class a bit and have some questions/comments about your implementation:
- If you aren't already aware of some of the reasons why people consider Singletons an anti-pattern, I suggest you do some research on the topic and make sure you're ok with the downsides.
- Your class, for the most part, seems to be wrapping a
SoundPool
with a key value pair structure despiteSoundPool
already being a key value pair structure. I would imagine you could do away with most of this class and just use theSoundPool
class directly. - If you don't want to use
SoundPool
directly for some reason, why not at least use the soundId as a key? It already appears to be unique, and it's what the calling code probably wants anyway. If not, you may want to do some checking to make sure that duplicate keys aren't entered, or take the key assignment out of the hands of the caller and simply return an id as the result of theaddSound
function. - Using both
mSoundPoolMap
andmAvailibleSounds
means you have to manage keys in two locations which could lead to them getting out of sync or some confusion as to why there are two fields holding the same information. Using onlymSoundPoolMap
would be sufficient and avoid duplication. This This highly voted question isn't quite the same, but it touches on a lot of good points why this kind of duplication can be bad.
Hope this helps!
Let me start by saying I have very limited Android experience. That said, I did look into the SoundPool
class a bit and have some questions/comments about your implementation:
- If you aren't already aware of some of the reasons why people consider Singletons an anti-pattern, I suggest you do some research on the topic and make sure you're ok with the downsides.
- Your class, for the most part, seems to be wrapping a
SoundPool
with a key value pair structure despiteSoundPool
already being a key value pair structure. I would imagine you could do away with most of this class and just use theSoundPool
class directly. - If you don't want to use
SoundPool
directly for some reason, why not at least use the soundId as a key? It already appears to be unique, and it's what the calling code probably wants anyway. If not, you may want to do some checking to make sure that duplicate keys aren't entered, or take the key assignment out of the hands of the caller and simply return an id as the result of theaddSound
function. - Using both
mSoundPoolMap
andmAvailibleSounds
means you have to manage keys in two locations which could lead to them getting out of sync or some confusion as to why there are two fields holding the same information. Using onlymSoundPoolMap
would be sufficient and avoid duplication. This highly voted question isn't quite the same, but it touches on a lot of good points why this kind of duplication can be bad.
Hope this helps!
Let me start by saying I have very limited Android experience. That said, I did look into the SoundPool
class a bit and have some questions/comments about your implementation:
- If you aren't already aware of some of the reasons why people consider Singletons an anti-pattern, I suggest you do some research on the topic and make sure you're ok with the downsides.
- Your class, for the most part, seems to be wrapping a
SoundPool
with a key value pair structure despiteSoundPool
already being a key value pair structure. I would imagine you could do away with most of this class and just use theSoundPool
class directly. - If you don't want to use
SoundPool
directly for some reason, why not at least use the soundId as a key? It already appears to be unique, and it's what the calling code probably wants anyway. If not, you may want to do some checking to make sure that duplicate keys aren't entered, or take the key assignment out of the hands of the caller and simply return an id as the result of theaddSound
function. - Using both
mSoundPoolMap
andmAvailibleSounds
means you have to manage keys in two locations which could lead to them getting out of sync or some confusion as to why there are two fields holding the same information. Using onlymSoundPoolMap
would be sufficient and avoid duplication. This highly voted question isn't quite the same, but it touches on a lot of good points why this kind of duplication can be bad.
Hope this helps!
Let me start by saying I have very limited Android experience. That said, I did look into the SoundPool
class a bit and have some questions/comments about your implementation:
- If you aren't already aware of some of the reasons why people consider Singletons an anti-pattern, I suggest you do some research on the topic and make sure you're ok with the downsides.
- Your class, for the most part, seems to be wrapping a
SoundPool
with a key value pair structure despiteSoundPool
already being a key value pair structure. I would imagine you could do away with most of this class and just use theSoundPool
class directly. - If you don't want to use
SoundPool
directly for some reason, why not at least use the soundId as a key? It already appears to be unique, and it's what the calling code probably wants anyway. If not, you may want to do some checking to make sure that duplicate keys aren't entered, or take the key assignment out of the hands of the caller and simply return an id as the result of theaddSound
function. - Using both
mSoundPoolMap
andmAvailibleSounds
means you have to manage keys in two locations which could lead to them getting out of sync or some confusion as to why there are two fields holding the same information. Using onlymSoundPoolMap
would be sufficient and avoid duplication. This highly voted question isn't quite the same, but it touches on a lot of good points why this kind of duplication can be bad.
Hope this helps!