In our code base
public ActionResult Copy(string id, string targetId)
{
//lot of similar code
Copy(sourcePageRef, destinationPageRef);
//lot of similar code
}
and
public ActionResult Move(string id, string targetId)
{
//lot of similar code
Move(sourcePageRef, destinationPageRef);
//lot of similar code
}
the problem is, Copy and Move have different signatures:
PageRef Copy(PageRef, PageRef)
and
void Move(PageRef, PageRef)
How can I refactor these methods to avoid duplication?
Thank you
If you don’t need the result of
Copy, you could still use anAction<string, string>or whatever the type is:That’s one option. It depends on what the “lot of similar code” is really doing, and whether the second block needs the results of the first block. For example, if you could do this:
… then that’s probably simpler than the refactoring-with-a-delegate approach.