using System.Collections.Generic;
public const decimal TAX = 1.1m;
public static void Main()
List<Thing> things = new List<Thing>{ new Thing("thing 1", 10, 2), new Thing("thing 2", 20, 3)};
IVisitor calc = new Calculate();
foreach(var t in things) {
Console.WriteLine("{0} - Total price = {1} - Total with tax = {2}", t.name, t.total, t.totalWithTax);
public interface IVisitor {
void Visit(IThing thing);
public interface IThing {
void Accept(IVisitor visitor);
public class Thing: IThing {
public decimal unitPrice;
public decimal totalWithTax;
public Thing(string name, int units, decimal unitPrice) {
this.unitPrice = unitPrice;
public void Accept(IVisitor visitor){
public class Calculate : IVisitor
public void Visit(IThing thing){
var _thing = (Thing)thing;
_thing.total = _thing.units * _thing.unitPrice;
_thing.totalWithTax = _thing.total * TAX;