{"id":5229,"date":"2014-03-30T19:57:27","date_gmt":"2014-03-30T19:57:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-do-i-call-different-methods-for-different-class-types-in-a-generic-message-receiver-collection-of-common-programming-errors\/"},"modified":"2014-03-30T19:57:27","modified_gmt":"2014-03-30T19:57:27","slug":"how-do-i-call-different-methods-for-different-class-types-in-a-generic-message-receiver-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-do-i-call-different-methods-for-different-class-types-in-a-generic-message-receiver-collection-of-common-programming-errors\/","title":{"rendered":"How do I call different methods for different class-types in a generic message-receiver?-Collection of common programming errors"},"content":{"rendered":"<p>It is possible to do what you&#8217;re suggesting, though it&#8217;s not very DRY, and I think the other suggestions here are more appropriate. Still, in the interest of completeness, here&#8217;s an approach close to what you were originally looking for:<\/p>\n<pre><code>void ReceiveMessage( IMessage message ) {\n  if( message as DummyMessage != null ) HandleMessage( message as DummyMessage );\n  else if( message as SillyMessage != null ) HandleMessage( message as SillyMessage );\n  \/\/ etc\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>It is possible to do what you&#8217;re suggesting, though it&#8217;s not very DRY, and I think the other suggestions here are more appropriate. Still, in the interest of completeness, here&#8217;s an approach close to what you were originally looking for: void ReceiveMessage( IMessage message ) { if( message as DummyMessage != null ) HandleMessage( message [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5229","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5229"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5229\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}