dimanche 7 janvier 2018

Applying Visitor pattern

I have been applying GOF design patterns to my code for several years. I have never really used the Visitor pattern (http://ift.tt/2vuEVGz). Please see the code below:

public Offer AssignOffer(OfferType offerType, IOfferValueCalculator valueCalculator)
{
    DateTime dateExpiring = offerType.CalculateExpirationDate();
    int value = valueCalculator.CalculateValue(this, offerType);
    var offer = new Offer(this, offerType, dateExpiring, value);
    _assignedOffers.Add(offer);
    NumberOfActiveOffers++;
    return offer;
}

Which I borrowed from here.

Is this an example of the Visitor pattern? If it is not the Visitor pattern, then what pattern could it be described as?

I believe an operation is defined on the Member class without changing the Member class. However, it is not a new operation. Therefore I am not sure.

Aucun commentaire:

Enregistrer un commentaire