beantownace
Active member
- Joined
- Feb 15, 2019
- Messages
- 40
- Programming Experience
- 5-10
Hello all,
I have more of a best practices question always fun to ask.
I have a class with a worker method that does a decent amount of logic. One part of the method I broke out was a part that calculates and updates two objects which exists within a ForEach loop. I created a Utility class that takes in the two object parameters into a Void method does the calculation and sets some of the object property values but the Void does not have a return as the objects are being passed by reference. I of course don't need to use ref before the param in this case and the external object to that utility method now has the updated objects. Also seems this is just updating the original passed object parameters and not making a copy of it as I have a Sum later and things are working as I expect so performance should be fine I think at least.
Is this bad practice to have a void external in a Helper type class for calculating? The reason I ask is that Void to another develop could cause confusion that it does not return anything unless you saw the referencing class using that void method. Curious thoughts on this as I am trying to break up the code as best I can but this one peaked my interest if it makes sense. Also only the CustomerSetup class will have use for that Calc method in the helper class so may want to just keep it within the setup class itself but it is a good use of a static method.
Example:
I have more of a best practices question always fun to ask.
I have a class with a worker method that does a decent amount of logic. One part of the method I broke out was a part that calculates and updates two objects which exists within a ForEach loop. I created a Utility class that takes in the two object parameters into a Void method does the calculation and sets some of the object property values but the Void does not have a return as the objects are being passed by reference. I of course don't need to use ref before the param in this case and the external object to that utility method now has the updated objects. Also seems this is just updating the original passed object parameters and not making a copy of it as I have a Sum later and things are working as I expect so performance should be fine I think at least.
Is this bad practice to have a void external in a Helper type class for calculating? The reason I ask is that Void to another develop could cause confusion that it does not return anything unless you saw the referencing class using that void method. Curious thoughts on this as I am trying to break up the code as best I can but this one peaked my interest if it makes sense. Also only the CustomerSetup class will have use for that Calc method in the helper class so may want to just keep it within the setup class itself but it is a good use of a static method.
Example:
Example:
public class CustomerWorker
{
public void CustomerSetup
{
//code
foreach(var invoice in invoices)
{
InvoicePO po = //call fills this object
InvoiceAcct acct = //call fills tis object
//calls an external calc method to change two properties in these
InvoiceHelper.CalcInvoice(po, acct);
//now objects are changed and does other things
}
}
}
public static class InvoiceHelper
{
public static void CalcInvoice(InvoicePO po, InvoiceAcct acct)
{
//does some calculations on po and acct
// no return of course but external static method call objects are updated
}
}
Last edited: