Sign in to follow this  

Design issue (or lack of it)

This topic is 4205 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 .....
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4205 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this