私はこのメソッドをC#で実装していますが、リファクタリングしたいと考えています。ちょうどブールとラインが多すぎます。何が最良のリファクタリングでしょうか。新しいクラスを作るのはちょっと残酷すぎるようですが、2人で簡単に切断するのは難しいようです。任意の洞察力またはポインタが評価されます。そのまま実際に、私は個人的にそれを残すだろうブールが多すぎるメソッドをリファクタリングする
private DialogResult CheckForSireRestrictionInSubGroup(bool deletingGroup,string currentId)
{
DialogResult result = DialogResult.No;
if (!searchAllSireList)
{
DataAccessDialog dlg = BeginWaitMessage();
bool isClose = false;
try
{
ArrayList deletedSire = new ArrayList();
ISireGroupBE sireGroupBE = sireController.FindSireGroupSearch();
if (sireGroupBE != null)
{
//if the current group is in fact the seach group before saving
bool currentGroupIsSeachGroup = sireGroupBE.TheSireGroup.id == currentId;
//if we have setting this group as search group
bool selectedAsSearchGroup = this.chkBoxSelectedSireGroup.Checked;
//if the group we currently are in is not longer the seach group(chk box was unchecked)
bool wasSearchGroup = currentGroupIsSeachGroup && !selectedAsSearchGroup;
//if the group is becoming the search group
bool becomesSearchGroup = !currentGroupIsSeachGroup && selectedAsSearchGroup;
//if the group being deleted is in fact the search group
bool deletingSearchGroup = deletingGroup && currentGroupIsSeachGroup;
//if the user checked the checkbox but he's deleting it, not a so common case, but
//we shouldn't even consider to delete sire in this case
bool deletingTemporarySearchGroup = deletingGroup && !currentGroupIsSeachGroup;
//if we are not deleting a temporary search group and it's either
//becoming one (without deleting it) or we already are the search group
bool canDeleteSires = !deletingTemporarySearchGroup &&
(becomesSearchGroup || currentGroupIsSeachGroup);
//we only delete sires if we are in search group
if (canDeleteSires)
{
if (deletingSearchGroup || wasSearchGroup)
{
// If we deleted all sires
deletedSire = new ArrayList();
deletedSire.AddRange(sireGroupBE.SireList);
}
else
{
//if we delete a few sire from the change of search group
deletedSire = GetDeleteSire(sireGroupBE.SireList);
}
}
EndWaitMessage(dlg);
isClose = true;
result = ShowSubGroupAffected(deletedSire);
}
}
finally
{
if (!isClose)
{
EndWaitMessage(dlg);
}
}
}
return result;
}
これは、ロジックを表現するクリーンな方法のように見える - 読みやすく、よくコメントされています。私は全く触らないだろう。 – dasblinkenlight
合意しました....それは時間がかかるかもしれませんが、それは可読です。 –
私は、現在のコードが読めるとは思っていますが、メソッドの目的を損なうと、エントリを削除します。ブール論理はそのままで、別の方法に移行することができます。メインメソッドでは、削除の主な問題に対処していない「サポート」コードを減らすことができます。 –