What is better to do in this type of scenario: populate fields or return an object?The situation is like this: I'm doing calculations to find the prices (inc tax, ex tax, discounted etc) of a product. Is there any advice or are there any guidelines on how to handle a return value?Populate fields:public class ProductPrice{    public int BasePrice;    public int IncTax;    public int ExTax;    // ...    public void GetPricesForProduct(int ProductID)    { /* Populate fields based on results */ }}Return object:public class PriceCalculator{    public ProductPrice GetPricesForProduct(int ProductID)    { /* Populate object fields and return object */ }}public class ProductPrice{    public int BasePrice;    public int IncTax;    public int ExTax;}I'm not sure I really like the first method, because the void return type doesn't make it clear what happens when the method executes. However, returning an object results in a class which has no functionality.
Populate fields or return object
object oriented design;api design
You're right to prefer the second method.  The first method would easily clutter a class with members that would better be suited torwards an object which represents those values.  Better still, add a method to ProductPrice which performs the calculation and change PriceCalculator to PriceFetcher which simply gets the raw values and instantiates ProductPrice.public class PriceFetcher{    public ProductPrice GetPricesForProduct(int ProductID)    { /* Populate object fields and return object */ }}public class ProductPrice{    public int BasePrice;    public int IncTax;    public int ExTax;    public float GetPrice()     { /* Perform calculation on given data */ }}This method has the added advantage that the object determines how the price is calculated and not the method which fetched the data, allowing you to do more complicated operations later with derived classes of ProductPrice and instantiate them using a factory in PriceFetcher.