Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • "it does look suspiciously cumbersome" In what way? Commented May 26, 2015 at 14:00
  • @pdr the 'if else if' train strongly reminds me of the switch-by-type situation, where polymorphism can often fit better. But I don't clearly see it here, either... Commented May 26, 2015 at 14:08
  • I see why it appears that way, but it's not. As opposed to "if this condition, use this type, else if this condition, use another type, etc" this is "if the current protocol supports X, use it; if it supports Y, use it; if it supports Z, use it." The alternative is to have no-op methods in each protocol class and call them all, which is pretty hard to follow at scale. "Can" methods, as you point out, are no different from is and as. Commented May 26, 2015 at 15:19
  • @pdr Yeah, that's exactly why I decided to try anyway :) Commented May 26, 2015 at 21:47