{"id":890,"date":"2020-09-23T11:58:00","date_gmt":"2020-09-23T17:58:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=890"},"modified":"2020-09-25T21:32:31","modified_gmt":"2020-09-26T03:32:31","slug":"interfaces-and-events","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2020\/09\/23\/interfaces-and-events\/","title":{"rendered":"Interfaces and events"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">There&#8217;s a question about why interfaces dont let you add event definitions to them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In fact since they just define a signature and leave the implementation else where I suppose they could. There&#8217;s no real compelling reason they couldn&#8217;t that I can think of.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They just don&#8217;t.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And so in the mean time what do you do ? How can you have the effect of an event without being able to define one ?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What you can do is define a method on the interface that takes a delegate and then implementors can call that delegate back at appropriate times &#8211; much like you&#8217;d do with raising an event.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The upside to using an interface is that you CAN apply it to disparate items &#8211; they dont have to all inherit from the same base class or control.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The downside is that its not an event so you can use addhandler to handle it. To be quite frank some of the bugs I&#8217;ve seen over the years suggest that AddHandler is overused. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&#8217;s a question about why interfaces dont let you add event definitions to them. In fact since they just define a signature and leave the implementation else where I suppose they could. There&#8217;s no real compelling reason they couldn&#8217;t that I can think of. They just don&#8217;t. And so in the mean time what do &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2020\/09\/23\/interfaces-and-events\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Interfaces and events&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-890","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=890"}],"version-history":[{"count":3,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/890\/revisions"}],"predecessor-version":[{"id":913,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/890\/revisions\/913"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}