Reputation: 83
Here's what I have to do;
public weapon(Texture2D knife, Texture2D pistol, Texture2D smg, Texture2D rifle,
SoundEffect knifeStab, SoundEffect pistolShot, SoundEffect smgShot, SoundEffect rifleShot)
{
}
Here's what I'd really like to do;
public weapon(Texture2D [knife, pistol, smg, rifle],
SoundEffect [knifeStab, pistolShot, smgShot, rifleShot])
{
}
Is there something like that? Would it be easier to send them all in a list/array of Texture2D's?
Upvotes: 0
Views: 1295
Reputation: 116471
When you pass multiple arguments to a method, you're basically saying that all of these are important to the method but otherwise unrelated. If that's the case, by all means pass the number of argument you need.
However, in many cases, arguments are related. In your example I imagine that the textures and the sound effects come in pairs. If that's the case, you could use encapsulate to express this.
That would not only reduce the number of arguments, but also keep related data together.
Upvotes: 1