ソートされたセット内のすべてのデコレータをトラッキングするにはどうしたらよいですか?デコレータパターン - デコレータをトラッキングするにはどうすればいいですか?
私の考えでは、コンストラクタのラップ処理中にデコレータを追加するだけのコレクションを用意していますが、現在の実装では、単一のアイテムを含むコレクションが返され続けます。誰かが私にこれを解決させる手助けはできますか
サービスはコンポーネントです。労働と設備はデコレータです。
public abstract class Service : IComparable<Service>
{
public abstract decimal JobCost { get; }
public virtual SortedSet<Service> Description { get; } = new SortedSet<Service>();
public void AddToStack() => Description.Add(this);
public int CompareTo(Service other)
{
// if both are labor services, then
if ((this is Labor) && (other is Labor))
{
return (this as Labor).Time.CheckIn.CompareTo((other as Labor).Time.CheckIn);
}
if (other is Equipment)
{
return -1;
}
return -2;
}
}
public abstract class ServiceDecorator : Service
{
public abstract override SortedSet<Service> Description { get; }
}
public class Labor : ServiceDecorator
{
private Service service;
private LaborRatesDual laborRates;
private LaborTime laborTime;
public Labor(Service service, LaborTime laborTime, LaborRatesDual laborRates)
{
this.service = service;
this.laborTime = laborTime;
this.laborRates = laborRates;
this.service.AddToStack();
}
public int WorkOrderNo { get; set; }
public string PO { get; set; }
public override SortedSet<Service> Description => new SortedSet<Service>(service.Description);
public int TechCount { get; set; } = 1;
public LaborTime Time
{
get { return laborTime; }
set { laborTime = value; }
}
public LaborRatesDual Rates
{
get { return laborRates; }
set { laborRates = value; }
}
// labor time to complete the service (labor time x tech count)
public TimeSpan Duration => TimeSpan.FromTicks(Time.Duration.Ticks * TechCount);
// get the cost for this particular labor service
public decimal Cost
{
...
}
// returns complete job cost, including the wrapped object
public override decimal JobCost => service.JobCost + Cost;
// helps identify is the service should be billed at continuous rate, or if the time
// should be billable using the dual-rate system
public bool IsContinuation { get; set; } = false;
}
public class Equipment : ServiceDecorator
{
Service service;
EquipmentTime time;
EquipmentRate rate;
public Equipment(Service service, EquipmentTime equipmentTime, EquipmentRate equipmentRate)
{
this.service = service;
this.time = equipmentTime;
this.rate = equipmentRate;
this.service.AddToStack();
}
public EquipmentTime Time
{
get { return time; }
set { time = value; }
}
public int UnitCount { get; set; } = 1;
public decimal Rate
{
get { return rate.Rate; }
set { rate.Rate = value; }
}
public bool UseCalendarDayCount { get; set; } = false;
// units x days
public int FullCount
{
...
}
public override SortedSet<Service> Description => new SortedSet<Service>(service.Description);
public decimal Cost => FullCount * Rate;
public override decimal JobCost => service.JobCost + Cost;
}