Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pass values in properties, or in parameters?

4 views
Skip to first unread message

Larry Bud

unread,
Aug 31, 2007, 9:49:00 AM8/31/07
to
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?

Kuldeep

unread,
Aug 31, 2007, 10:07:35 AM8/31/07
to
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" <larryb...@yahoo.com> wrote in message
news:1188568140....@r29g2000hsg.googlegroups.com...

Alex Meleta

unread,
Aug 31, 2007, 10:12:58 AM8/31/07
to
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

LB> I'm writing a class to create a specifically formatted fixed width
LB> file. It's 800 characters wide, consisting of approx 30 fields.
LB>
LB> So I need to pass 30 variables, maybe 10 are required. Should I
LB> write the function to accept these as parameters in a method, or
LB> should I make them properties? Can I make certain properties
LB> required?
LB>


sloan

unread,
Aug 31, 2007, 11:30:07 AM8/31/07
to

There is a third solution.

Write a wrapper object, containing all the parameters.


public class EmployeeController

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.EmployeeUUID = Guid.NewGuid();
myArg.LastName = "Smith";
myArg.FirstName = "John";
myArg.CreateDate = DateTime.Now;


EmployeeController.UpdateEmployee ( 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" <larryb...@yahoo.com> wrote in message
news:1188568140....@r29g2000hsg.googlegroups.com...

Larry Bud

unread,
Aug 31, 2007, 11:52:57 AM8/31/07
to
> "Larry Bud" <larrybud2...@yahoo.com> wrote in message

>
> news:1188568140....@r29g2000hsg.googlegroups.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?- Hide quoted text -
>
> - Show quoted text -

Thanks to all. This is a pretty elegant solution. Turns out there's
*51* fields. This beats writing 51 Set Property statements

sloan

unread,
Aug 31, 2007, 12:22:48 PM8/31/07
to

And when you need a new (extra) property, you don't change the signatures
anywhere.


Today:

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

}

1 Year from Now:


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

public List <Guid> JobFunctionUUIDs
public Guid CubicleLocationUUID

}


While your controller will handle the new values, you don't have change the
method calls.

EmployeeController.UpdateEmployee ( myArg );

will always be

EmployeeController.UpdateEmployee ( myArg) ;

forever more.


"Larry Bud" <larryb...@yahoo.com> wrote in message

news:1188575577.8...@g4g2000hsf.googlegroups.com...

Larry Bud

unread,
Aug 31, 2007, 12:49:35 PM8/31/07
to

> 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"??

sloan

unread,
Aug 31, 2007, 3:32:49 PM8/31/07
to
//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" <larryb...@yahoo.com> wrote in message

news:1188578975.6...@d55g2000hsg.googlegroups.com...

Larry Bud

unread,
Aug 31, 2007, 3:55:58 PM8/31/07
to
On Aug 31, 3:32 pm, "sloan" <sl...@ipass.net> wrote:
> //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" <larrybud2...@yahoo.com> wrote in message

>
> news:1188578975.6...@d55g2000hsg.googlegroups.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"??- Hide quoted text -

>
> - Show quoted text -

Ok, what was confusing me is that you wrote EmployeeArg in one place,
and EmployeeArgs in another place.

Thx!

sloan

unread,
Aug 31, 2007, 4:51:52 PM8/31/07
to
Oh yeah, now I see that. Sorry.

I was just typing away from pseudo code ............

"Larry Bud" <larryb...@yahoo.com> wrote in message

news:1188590158....@g4g2000hsf.googlegroups.com...

0 new messages