10秒ごとに3つのhttpリクエストをWebサービスに送信します。応答は、キャッシュクラス内の3つのメソッド(httpクエリ/リクエストごとに1つ)に渡され、前回から応答の内容が変更されたかどうかを確認します。
生の応答コンテンツを文字列に変換し、キャッシュクラスにプライベート文字列として保存されている古い応答と比較します。正常に機能しますが、次のように、このアプローチには重複したコードがたくさんあります。
class Cache
{
private HubClient _hubClient;
private string oldIncidentAppointment;
private string oldIncidentGeneral;
private string oldIncidentUntreated;
public Cache(HubClient hubClient)
{
_hubClient = hubClient;
}
public bool IsIncidentAppointmentNew(string currentIncidentAppointment)
{
if (XElement.Equals(oldIncidentAppointment, currentIncidentAppointment))
{
return false;
}
else
{
oldIncidentAppointment = currentIncidentAppointment;
_hubClient.SendToHub();
return true;
}
}
public bool IsIncidentUntreatedNew(string currentIncidentUntreated)
{
if (XElement.Equals(oldIncidentUntreated, currentIncidentUntreated))
{
return false;
}
else
{
oldIncidentUntreated = currentIncidentUntreated;
_hubClient.SendToHub();
return true;
}
}
public bool IsIncidentGeneralNew(string currentIncidentGeneral)
{
if (XElement.Equals(oldIncidentGeneral, currentIncidentGeneral))
{
return false;
}
else
{
oldIncidentGeneral = currentIncidentGeneral;
_hubClient.SendToHub();
return true;
}
}
}
これを、現在および将来のすべてのhttpクエリメソッドの新旧のコンテンツを比較する一般化されたメソッドにリファクタリングするにはどうすればよいですか?