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?
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...
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>
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...
Thanks to all. This is a pretty elegant solution. Turns out there's
*51* fields. This beats writing 51 Set Property statements
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...
I'm not understanding how this forces lname and fname. Shouldn't
EmployeeArg be "New"??
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...
Ok, what was confusing me is that you wrote EmployeeArg in one place,
and EmployeeArgs in another place.
Thx!
I was just typing away from pseudo code ............
"Larry Bud" <larryb...@yahoo.com> wrote in message
news:1188590158....@g4g2000hsf.googlegroups.com...