473,779 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass values in properties, or in parameters?

I'm writing a class to create a specifically formatted fixed width
file. It's 800 characters wide, consisting of approx 30 fields.

So I need to pass 30 variables, maybe 10 are required. Should I write
the function to accept these as parameters in a method, or should I
make them properties? Can I make certain properties required?

Aug 31 '07 #1
5 1455
Hi Larry,

Having Properties for all those parameters which go to and fro is possibly
the best solution.
Moreover, it is not tedious enough to handle them as properties and at the
same time
comes in very handy for most of your functionalities

Kuldeep

"Larry Bud" <la**********@y ahoo.comwrote in message
news:11******** *************@r 29g2000hsg.goog legroups.com...
I'm writing a class to create a specifically formatted fixed width
file. It's 800 characters wide, consisting of approx 30 fields.

So I need to pass 30 variables, maybe 10 are required. Should I write
the function to accept these as parameters in a method, or should I
make them properties? Can I make certain properties required?

Aug 31 '07 #2
Hi Larry,

It depents on how you store the value there and format of file. Anyway, setting
the params by properties is clear solution. If object is flexible you can
combine these too methods - props to accept neccessary params and method
for aditional params, but it depends on format.

Regards, Alex
[TechBlog] http://devkids.blogspot.com

LBI'm writing a class to create a specifically formatted fixed width
LBfile. It's 800 characters wide, consisting of approx 30 fields.
LB>
LBSo I need to pass 30 variables, maybe 10 are required. Should I
LBwrite the function to accept these as parameters in a method, or
LBshould I make them properties? Can I make certain properties
LBrequired?
LB>
Aug 31 '07 #3

There is a third solution.

Write a wrapper object, containing all the parameters.
public class EmployeeControl ler

public static void UpdateEmployee ( EmployeeArgs arg )
{

}
public class (or struct) EmployeeArgs
{
public Guid EmployeeUUID (property here)
public string LastName
public string FirstName
public DateTime CreateDate
public DateTIme HireDate

}

EmployeeArgs myArg = new EmployeeArgs ( ) ;
myArg.EmployeeU UID = Guid.NewGuid();
myArg.LastName = "Smith";
myArg.FirstName = "John";
myArg.CreateDat e = DateTime.Now;
EmployeeControl ler.UpdateEmplo yee ( myArg);
With 30 (and some optional) parameters, I'd write the wrapper arg object.

You'll notice I didnt' specify the HireDate, aka, it is optional. Your
controller class can determine what to do in an omitted HireDate.

ALSO.

If you have some MANDATORY properties, then you can expose the constructor
to the wrapper arg.
public class EmployeeArgs
{
//no default constructor
public EmployeeArg ( string lname, string fname)
{
this.LastName = lname;
this.FirstName = fname;
}

public Guid EmployeeUUID (property here)
public string LastName
public string FirstName
public DateTime CreateDate
public DateTIme HireDate

}
This way, you're forcing lname and fname.


"Larry Bud" <la**********@y ahoo.comwrote in message
news:11******** *************@r 29g2000hsg.goog legroups.com...
I'm writing a class to create a specifically formatted fixed width
file. It's 800 characters wide, consisting of approx 30 fields.

So I need to pass 30 variables, maybe 10 are required. Should I write
the function to accept these as parameters in a method, or should I
make them properties? Can I make certain properties required?

Aug 31 '07 #4
If you have some MANDATORY properties, then you can expose the constructor
to the wrapper arg.

public class EmployeeArgs
{
//no default constructor
public EmployeeArg ( string lname, string fname)
{
this.LastName = lname;
this.FirstName = fname;

}

public Guid EmployeeUUID (property here)
public string LastName
public string FirstName
public DateTime CreateDate
public DateTIme HireDate

}

This way, you're forcing lname and fname.
I'm not understanding how this forces lname and fname. Shouldn't
EmployeeArg be "New"??

Aug 31 '07 #5
//hide the default constructor
private EmployeeArg ( /* no default constructor */ ) {}
public EmployeeArg ( string lname, string fname)
{
this.LastName = lname;
this.FirstName = fname;

}

The syntax above IS THE CONSTRUCTOR in C#. (2 constuctors, 1 public , 1
private)
Aka, you can only do this:

EmployeeArg arg = new EmployeeArg ( "Jones" , "Mary") ;

and you can't do this:

EmployeeArg arg = new EmployeeArg (); // because the default constructor is
private, thus you can't get to it.
basically here you are saying that you MUST provide a lastname and
firstname, else you can't construct the object.
aka, this is good for mandatory values.


"Larry Bud" <la**********@y ahoo.comwrote in message
news:11******** **************@ d55g2000hsg.goo glegroups.com.. .
>
>If you have some MANDATORY properties, then you can expose the
constructor
to the wrapper arg.

public class EmployeeArgs
{
//no default constructor
public EmployeeArg ( string lname, string fname)
{
this.LastName = lname;
this.FirstName = fname;

}

public Guid EmployeeUUID (property here)
public string LastName
public string FirstName
public DateTime CreateDate
public DateTIme HireDate

}

This way, you're forcing lname and fname.

I'm not understanding how this forces lname and fname. Shouldn't
EmployeeArg be "New"??

Aug 31 '07 #6

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

Similar topics

7
21635
by: Zlatko Matiæ | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the server ? Is it possible to use parameters in pass-through queries ? An additional question: Is it possible to connect to a database on MySQL or PostgreSQL using ADO ? Is it possible to execute pass-through queries with parameters, using ADO...
2
4725
by: Mountain Bikn' Guy | last post by:
It is known that one cannot pass arguments as ref or out in a marshal-by-reference class. My problem is that I have a C DLL (and C# wrapper) that I need to isolate in an AppDomain and then I need to interact with many objects in that DLL and wrapper by reference. (So the classes inherit from MBRO.) While my app is running, I need to obtain info from objects in the 2nd app domain frequently/speedily and I need update the GUI; and I need to...
5
3960
by: Ben | last post by:
Hi I am using a User Control which is referenced by an ASPX page. How can I pass a string parameter to the user control, from the base ASPX page. Thanks Ben
14
9888
by: Derek Basch | last post by:
This one has always bugged me. Is it better to just slap a "self" in front of any variable that will be used by more than one class method or should I pass around variable between the methods? Flamewar........NOW! jk, I really do want other opinions. Thanks, Derek
4
9119
by: kinaxx | last post by:
Hello, now I'm learning progamming language in university. but i have some question. in textbook. says there are four passing Mechanism 1) pass by value (inother words : call by value) 2) pass by reference (inother words: call by reference) 3) pass by value-result <- i have question this subject . 4) pass by name
2
3216
by: gumby | last post by:
I would like to call this stored procedure, but I am unable to pass parameters to the @Start and @End. Is thier a way to pass parameters to a pass through query from MS Access? SELECT COUNT(dbo.tblPersActionHistory.PersActionID) AS , .fn_FindStartPayPeriod(dbo.tblPersActionHistory.PersActionID, 2) AS FROM dbo.tblPersActionLog INNER JOIN
24
55237
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new EventHandler(Onbutton_click); I want to pass more information related that event. & want to use that
12
11111
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
6
1700
by: =?Utf-8?B?Unlhbg==?= | last post by:
I am trying to pass a value from a texbox in Form1 to a textbox in Form2 using properties in VS2005 but it doesn't work; please help (project is attached). Code for Game Class: using System; using System.Collections.Generic; using System.Text;
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9930
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
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.