tag:blogger.com,1999:blog-15136575.post5722810463043134099..comments2023-10-17T12:00:16.772+01:00Comments on Code rant: Interface + Extension Methods = MixinMike Hadlowhttp://www.blogger.com/profile/16441901713967254504noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-15136575.post-65457556057104399962012-05-19T16:42:41.886+01:002012-05-19T16:42:41.886+01:00*You'd*You'dAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-80907428765908961612012-05-19T16:41:58.504+01:002012-05-19T16:41:58.504+01:00@Anon: You've need the relevant Using tag at t...@Anon: You've need the relevant Using tag at the top anyway to access the interface ... just put the extension methods in a public static class in the same namespace as the interface.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-67624706327008599062009-04-07T23:46:00.000+01:002009-04-07T23:46:00.000+01:00This is not a mixin.. it's not even a trait. You s...This is not a mixin.. it's not even a trait. You still ended up implementing everything required in the interface, and you still need to put a "using ... " statement at the top of every file which you're using extension methods in.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-32025184068038410892008-06-12T08:54:00.000+01:002008-06-12T08:54:00.000+01:00Hi Daniel,You are right, it's a limited form of ex...Hi Daniel,<BR/><BR/>You are right, it's a limited form of extensibility compared to inheritance, but then it's more flexible in it's application; a single class can have many different mixins applied to it. you can only have one base class. In a way mixins better support the open-closed principle by allowing an addition of functionality (by adding extension methods of the interface) without any change to existing code.<BR/><BR/>It's true you can't access protected members or add new fields, but because a mixin is based around an interface you have that interface to tell you what you need to know about the class being mixed-into.<BR/><BR/>I think it's important not to see mixins as somehow replacing inheritance. They are just another design pattern you can use to help you factor your code.Mike Hadlowhttps://www.blogger.com/profile/16441901713967254504noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-45893351951489813572008-06-11T21:12:00.000+01:002008-06-11T21:12:00.000+01:00I am no 100% sure myself of the "true" definition ...I am no 100% sure myself of the "true" definition of a mixin but one has to consider that the fact that it's not possible to either create instance variables (for both class and interface extension) or access protected members in an extension method (for a class extension) makes things difficult to truly extend such types ?Anonymousnoreply@blogger.com