Hi all
This is more a design problem than a programming one
Ive done some reading and it seems that having a function with more than 3 or 4 arguments is somewhat unacceptable ( something wrong with the design of the program ).
I know how to reduce the arguments, but it requires more work in the main function. Take this for example...
I have a draw Rectangle function here ( For SDL ), takes the x, y, width, hieght, inside colour, outside colour and the thickness of the rectangle.
void drawRect ( int x, int y, int w, int h, SDL_Surface* screen, int colourOutline, int thickness, int fill );
Some say its too many arguments, I could write it like this:
void drawRect ( SDL_Rect rect, SDL_Surface* screen, scheme* pScheme );
where the SDL_Rect holds x, y, width and hieght
and pScheme holds the colours and thickness
Even though the second bit of code looks somewhat nicer, every time i want to create a different type of rectangle i have to change the rect and pScheme attributes in the main function, which does not confine it to one line.
The main function will end up looking like this:
1 2 3 4 5 6 7 8 9
|
rectArg.x = 0;
rectArg.y = 200;
rectArg.w = 500;
rectArg.h = 100;
schemeArg.colourOutline = 0xFF00FF;
schemeArg.thickness = 3;
schemeArg.fill = 0x00FF00;
drawRect ( &rectArg, screen, &schemeArg );
|
instead of this:
drawRect ( 0, 200, 500, 100, screen, 0xFF00FF, 3, 0x00FF00 );
Which is all on one line ( Much nicer )
Im not sure which approach to take! Many opinions on this matter would be much appreciated
Many Thanks, Super_Stinger