Re: Why to use Moose roles ever?
[email protected] (Jed Lund) Wed, 10 Aug 2016 07:43:47 -0700
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <CAM4-=+OUh_NfrC9x4oN2SNdbc72VGfgwxTrLfevf-M3di33Lmw@mail.gmail.com> |
--94eb2c068cfa7ab9140539b8ae30 Content-Type: text/plain; charset=UTF-8 Victor, My experience has always been that Moose is as flexible as possible without causing fundamental logical conflicts (And their companion hard to debug issues). It is important to note that a Moose Role is not a one for one match to other programming languages implementations for a role. https://metacpan.org/pod/distribution/Moose/lib/Moose/Manual/Roles.pod#Roles-Versus-Abstract-Base-Classes The question you are asking also falls in the line of a bigger question that is partially outside of the scope of Moose implementation. http://www.javaworld.com/article/2076814/core-java/inheritance-versus-composition--which-one-should-you-choose-.html https://en.wikipedia.org/wiki/Composition_over_inheritance Are you aware of the following two pieces of Moose documentation? The may help to resolve some specifics around any specific implementations. https://metacpan.org/pod/distribution/Moose/lib/Moose/Manual/Roles.pod#METHOD-CONFLICTS https://metacpan.org/pod/distribution/Moose/lib/Moose/Manual/Roles.pod#METHOD-EXCLUSION-AND-ALIASING Best Regards, Jed On Wed, Aug 10, 2016 at 6:00 AM, Victor Porton <[email protected]> wrote: > Moose roles have some limitations, such as inability to override a > method in a class which "with"es the role. > > But I can use an abstract base class instead of a role. > > Are there any real situations where roles are better than base classes? > With examples, please. > --94eb2c068cfa7ab9140539b8ae30 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Victor,<div><br></div><div>My experience has always been t= hat Moose is as flexible as possible without causing fundamental logical co= nflicts (And their companion hard to debug issues).=C2=A0 It is important t= o note that a Moose Role is not a one for one match to other programming la= nguages implementations for a role.</div><div><br></div><div>=C2=A0 =C2=A0 = <a href=3D"https://metacpan.org/pod/distribution/Moose/lib/Moose/Manual/Rol= es.pod#Roles-Versus-Abstract-Base-Classes">https://metacpan.org/pod/distrib= ution/Moose/lib/Moose/Manual/Roles.pod#Roles-Versus-Abstract-Base-Classes</= a><br></div><div><br></div><div>The question you are asking also falls in t= he line of a bigger question that is partially outside of the scope of Moos= e implementation.</div><div><br></div><div>=C2=A0 =C2=A0<a href=3D"http://w= ww.javaworld.com/article/2076814/core-java/inheritance-versus-composition--= which-one-should-you-choose-.html">http://www.javaworld.com/article/2076814= /core-java/inheritance-versus-composition--which-one-should-you-choose-.htm= l</a><br></div><div><br></div><div>=C2=A0 =C2=A0<a href=3D"https://en.wikip= edia.org/wiki/Composition_over_inheritance">https://en.wikipedia.org/wiki/C= omposition_over_inheritance</a></div><div><br></div><div>Are you aware of t= he following two pieces of Moose documentation?=C2=A0 The may help to resol= ve some specifics around any specific implementations.</div><div><br></div>= <div>=C2=A0 =C2=A0<a href=3D"https://metacpan.org/pod/distribution/Moose/li= b/Moose/Manual/Roles.pod#METHOD-CONFLICTS">https://metacpan.org/pod/distrib= ution/Moose/lib/Moose/Manual/Roles.pod#METHOD-CONFLICTS</a><br></div><div><= br></div><div>=C2=A0 =C2=A0<a href=3D"https://metacpan.org/pod/distribution= /Moose/lib/Moose/Manual/Roles.pod#METHOD-EXCLUSION-AND-ALIASING">https://me= tacpan.org/pod/distribution/Moose/lib/Moose/Manual/Roles.pod#METHOD-EXCLUSI= ON-AND-ALIASING</a><br></div><div><br></div><div>Best Regards,</div><div><b= r></div><div>Jed</div></div><div class=3D"gmail_extra"><br><div class=3D"gm= ail_quote">On Wed, Aug 10, 2016 at 6:00 AM, Victor Porton <span dir=3D"ltr"= ><<a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]</= a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0= 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Moose roles have som= e limitations, such as inability to override a<br> method in a class which "with"es the role.<br> <br> But I can use an abstract base class instead of a role.<br> <br> Are there any real situations where roles are better than base classes?<br> With examples, please.<br> </blockquote></div><br></div> --94eb2c068cfa7ab9140539b8ae30--