473,472 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: Trick needed - passing a large number of parameters to a class

On Jul 21, 1:27*pm, eran <kale...@gmail.comwrote:
- Use a params struct
... that has a constructor to set all the members.
What bothers me is this: I'd really like to minimize the chance that
the caller will miss setting one of the params.
That problem is solved... :)

Ali
Jul 21 '08 #1
3 1874
On Jul 21, 11:58*pm, acehr...@gmail.com wrote:
On Jul 21, 1:27*pm, eran <kale...@gmail.comwrote:
- Use a params struct

... that has a constructor to set all the members.
But then, values will have to be copied into the struct and then again
into the class.

I'd recommend using getters/setters the way they are implemented in
FLTK, for example, using parameter-based method overriding:

instance.varName (); /* returns the value */
instance.varName (value); /* sets the value */

As for checking if all the parameters are set, you should set default
values in the constructor, and before beginning to use the parameters
check if they have been set by the class's user.

Hope that helps
Jul 21 '08 #2
On Jul 21, 2:31*pm, khalid...@gmail.com wrote:
On Jul 21, 11:58*pm, acehr...@gmail.com wrote:
On Jul 21, 1:27*pm, eran <kale...@gmail.comwrote:
- Use a params struct
... that has a constructor to set all the members.

But then, values will have to be copied into the struct and then again
into the class.
Not "have to" for two reasons:

- struct members may be references to existing objects

- the compiler may optimize away the copy
I'd recommend using getters/setters the way they are implemented in
FLTK, for example, using parameter-based method overriding:

instance.varName (); /* returns the value */
instance.varName (value); /* sets the value */
[This is not related to this topic, and completely subjective, but I
strongly recommend against using the same name for getters and
setters. It looks good on paper but very confusing.]

Now, what happened to the concern of copying? Wouldn't the setter copy
the value?
As for checking if all the parameters are set, you should set default
values in the constructor, and before beginning to use the parameters
check if they have been set by the class's user.
That method would first default construct and then assign. Since
assignment involves destructing and copying, I don't think you are
really concerned about the cost of the method I proposed. Maybe I
misunderstood you. Why did you object using a constructor to set the
parameters?

Additionally, you method requires that every member must be
assignable, which not every type are.
Hope that helps
Sure, but that is inferior to using a constructor. Besides, your
method does not address the OP's requirement at all: eran said "I'd
really like to minimize the chance that the caller will miss setting
one of the params."

Ali
Jul 21 '08 #3
kh*******@gmail.com wrote:
On Jul 21, 11:58 pm, acehr...@gmail.com wrote:
>On Jul 21, 1:27 pm, eran <kale...@gmail.comwrote:
>>- Use a params struct
... that has a constructor to set all the members.

But then, values will have to be copied into the struct and then again
into the class.
Who copy? The class could work directly on the data.
I'd recommend using getters/setters the way they are implemented in
FLTK, for example, using parameter-based method overriding:
Which is always the sign of a bad design. How do you make sure they are
all called or which ones upset the state of the class?

--
Ian Collins.
Jul 22 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Mac | last post by:
Is there a way to mimic the behaviour of C/C++'s preprocessor for macros? The problem: a lot of code like this: def foo(): # .... do some stuff if debug: emit_dbg_obj(DbgObjFoo(a,b,c)) #...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
1
by: Darsin | last post by:
Hi all, I am a new programmer to C# and i am having a following problem. I want to make a single method which takes a variable length array and display it contents. i have defined the method as:...
8
by: Brett Romero | last post by:
I'd like to know when exactly the this. keyword is needed. For example: public class Combination { private long n = 0; private long k = 0; private long data = null; public...
2
by: Colin McGuire | last post by:
Hi everyone. This is a question and something new and neat I have found. But to recap - a few months back I learnt about overloading, how to create the same method with a different signature. With...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
11
by: Macca | last post by:
Hi, I'm writing an application that will pass a large amount of data between classes/functions. In C++ it was more efficient to send a pointer to the object, e.g structure rather than passing...
4
by: MicroMoth | last post by:
Hi, I'm trying to write a update method, in which when the user clicks the update button the update method is passed 10 form fields. Then a update SQL is run to update the database. My question...
0
by: eran | last post by:
Thank you all for answering. I'm afraid relying on setters does not solve the problem of omitting the init of one of the params. Using default values and validation might help, but not when...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.