Skip to main content
Tweeted twitter.com/StackSoftEng/status/875686970147655681
We hates horizontal scroll. We hates it. Nasty evil scroll.
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

Please see the code below:

public List<DenominationDTO> CalculateChange(decimal 
 cost,       decimal paymentReceivedcost, string currencySymbol)
        {decimal paymentReceived, 
        string currencySymbol)
{
    var currency = CurrencyFactory.Create(currencySymbol);
            var denomination = DenominationFactory.Create(0,0);
    DenominationsCalculator = DenominationsCalculatorFactory.Create(
      DenominationsCalculator = DenominationsCalculatorFactory.Create(currency, 
        denomination, 
        cost, paymentReceived);
        paymentReceived);
    return Mapper.Map<List<DenominationDTO>>(
        DenominationsCalculator.GetDenominations().ToList());
        }

DenominationFactory is used to create an instance of an immutable value class. Immutable classes should not have a zero argument constructor based on what I have read. If they could have a single valued constructor, then I could just inject the class that is created by DenominationFactory into the constructor of the class that contains CalculateChange.

Can an immutable class have a zero argument constructor? According to this link it should not: https://www.codeproject.com/Articles/1043301/Immutable-objects-in-Csharp

I am talking strictly from a best practice perspective using DDD and a Rich Domain Model.

Please see the code below:

public List<DenominationDTO> CalculateChange(decimal cost, decimal paymentReceived, string currencySymbol)
        {
            var currency = CurrencyFactory.Create(currencySymbol);
            var denomination = DenominationFactory.Create(0,0);
            DenominationsCalculator = DenominationsCalculatorFactory.Create(currency, denomination, cost, paymentReceived);
            return Mapper.Map<List<DenominationDTO>>(DenominationsCalculator.GetDenominations().ToList());
        }

DenominationFactory is used to create an instance of an immutable value class. Immutable classes should not have a zero argument constructor based on what I have read. If they could have a single valued constructor, then I could just inject the class that is created by DenominationFactory into the constructor of the class that contains CalculateChange.

Can an immutable class have a zero argument constructor? According to this link it should not: https://www.codeproject.com/Articles/1043301/Immutable-objects-in-Csharp

I am talking strictly from a best practice perspective using DDD and a Rich Domain Model.

Please see the code below:

public List<DenominationDTO> CalculateChange( 
        decimal cost, 
        decimal paymentReceived, 
        string currencySymbol)
{
    var currency = CurrencyFactory.Create(currencySymbol);
    var denomination = DenominationFactory.Create(0,0);
    DenominationsCalculator = DenominationsCalculatorFactory.Create(
        currency, 
        denomination, 
        cost, 
        paymentReceived);
    return Mapper.Map<List<DenominationDTO>>(
        DenominationsCalculator.GetDenominations().ToList());
}

DenominationFactory is used to create an instance of an immutable value class. Immutable classes should not have a zero argument constructor based on what I have read. If they could have a single valued constructor, then I could just inject the class that is created by DenominationFactory into the constructor of the class that contains CalculateChange.

Can an immutable class have a zero argument constructor? According to this link it should not: https://www.codeproject.com/Articles/1043301/Immutable-objects-in-Csharp

I am talking strictly from a best practice perspective using DDD and a Rich Domain Model.

Source Link
w0051977
  • 7.1k
  • 8
  • 67
  • 96

Can an immutable class have a zero argument constructor?

Please see the code below:

public List<DenominationDTO> CalculateChange(decimal cost, decimal paymentReceived, string currencySymbol)
        {
            var currency = CurrencyFactory.Create(currencySymbol);
            var denomination = DenominationFactory.Create(0,0);
            DenominationsCalculator = DenominationsCalculatorFactory.Create(currency, denomination, cost, paymentReceived);
            return Mapper.Map<List<DenominationDTO>>(DenominationsCalculator.GetDenominations().ToList());
        }

DenominationFactory is used to create an instance of an immutable value class. Immutable classes should not have a zero argument constructor based on what I have read. If they could have a single valued constructor, then I could just inject the class that is created by DenominationFactory into the constructor of the class that contains CalculateChange.

Can an immutable class have a zero argument constructor? According to this link it should not: https://www.codeproject.com/Articles/1043301/Immutable-objects-in-Csharp

I am talking strictly from a best practice perspective using DDD and a Rich Domain Model.