Design issue (or lack of it)

Started by
4 comments, last by The C modest god 17 years, 10 months ago
I have a method with a lot of paramters, and I know its a NO NO. How should I solve this problem? I need all the parameters. Should I make initiation of the object without any paramters and only later do methods to set the parameters? but then I need that the object(Animated button) will function also when the paramters are not set. Any ideas how to solve this? Here is the initiation method:

void 
AnimationButton::Initialize (ObjectPoint2D & Parent, DWORD PixelX, DWORD PixelY, string Text, BYTE Alpha, BYTE Red, BYTE Green, BYTE Blue, MultiUseSFX & PointSFX, MultiUseSFX & PressSFX, Timer & Tmr, VirtualMouse & VMouse, SpriteFont & Font, TransImageSource & Pattern, Sprite & Pressed, SpriteAnimation & Pointed, BaseClass * pData, void (*pJob)(BaseClass * pData), BOOL & ActivationSwitch)
{
	this->Position.Initialize (Parent, PixelX, PixelY);
	this->BasicInitialize (Text, Alpha, Red, Green, Blue, PointSFX, PressSFX, Tmr, VMouse, Font, Pattern, Pressed, Pointed, pData, pJob, ActivationSwitch);
}

Thanks in advance.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Advertisement
Perhaps you could group all or most of these parameters into a structure or class if they have something in common? For example, you could call it AnimationParameters or something.
First thing i can think of is that you can atleast group: DWORD PixelX, DWORD PixelY into a 'POINT pos' structure and: BYTE Alpha, BYTE Red, BYTE Green, BYTE Blue into 'DWORD color'. Secondary you can do as the guy above mentioned create a init structure 'Microssoft way':

struct AnimBtnInit {
ObjectPoint2D *parent;
POINT pos;
DWORD color;
....... and so on ......
};

AnimationButton::Initialize(AnimBtnInit &init) {
this->Position.Initialize(*init.parent, init.pos.x, init.pos.y);
.... and so on .....
}
Crush your enemies, see them driven before you, and hear the lamentations of their women!
That's IMPRESSIVE! :D
It's hard to make many suggestions when I don't really know your architecture, or what you're trying to achieve, but I'll give some thoughts anyway.
I suggest you further break up the functionality of AnimationButton, as it seems it's a somewhat "do-all" class. For instance, passing an animatable sprite containing states instead of 3 sprites that are handled within the class, or maybe have a composite object that takes the base class of the animated sprite/font and lets you draw arbitrary "stuff" on it.. and is it really necessary to hold this VMouse reference? Can't the button just register itself at a higher level to receive events from it? Same goes for the timer, depending on what the timer is doing exactly..
Sorry if that's not helpful, it's hard to infer what AnimationButton is doing/is supposed to be doing from the snippet.
Daniel
I think FBMachine has quite a point there.
Also, you might consider setting some properties of your button to sensible defaults in Initialize, and then have additional SetXXXX-methods for the other stuff.
So, for example, initialize won't receive the sound effects. By default, the button is silent. However, by invoking button.setClickedSFX( soundeffect ) you can set it.
Quote:Original post by FBMachine
That's IMPRESSIVE! :D
It's hard to make many suggestions when I don't really know your architecture, or what you're trying to achieve, but I'll give some thoughts anyway.
I suggest you further break up the functionality of AnimationButton, as it seems it's a somewhat "do-all" class. For instance, passing an animatable sprite containing states instead of 3 sprites that are handled within the class, or maybe have a composite object that takes the base class of the animated sprite/font and lets you draw arbitrary "stuff" on it.. and is it really necessary to hold this VMouse reference? Can't the button just register itself at a higher level to receive events from it? Same goes for the timer, depending on what the timer is doing exactly..
Sorry if that's not helpful, it's hard to infer what AnimationButton is doing/is supposed to be doing from the snippet.
Daniel

Didnt understand you about the mouse, what do you mean by registering itself?
I did thought about doing a button style class that will contain some of the paramters.
Also setting some of the paramters after creation may be a good idead, maybe I will do it to the style. So if I change the style it will affect all the buttons using it.

Thanks.

It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.

This topic is closed to new replies.

Advertisement