namespace domain { using System; using System.Collections.Generic; public interface IComposition { void SplitFor(Percent percent) where Commodity : ICommodity; IQuantity PercentageOf(IQuantity quantity) where Commodity : ICommodity, new(); Percent PercentageFor() where Commodity : ICommodity; } public class CommoditySplits : IComposition { IDictionary splits = new Dictionary(); public void SplitFor(Percent percent) where Commodity : ICommodity { splits[typeof (Commodity)] = percent; } public IQuantity PercentageOf(IQuantity quantity) where Commodity : ICommodity, new() { return new Commodity().PercentageFrom(this).Reduce(quantity); } public Percent PercentageFor() where Commodity : ICommodity { return splits.ContainsKey(typeof(Commodity)) ? splits[typeof (Commodity)] : Percent.Zero; } } }