RE: how to: extract interface of class with methods from a superclass
"Donaldson, John" <[email protected]> Mon, 23 Sep 2013 07:04:48 +0000
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <716D07F3CBA94244A0922E7A99837C3A109FBAE4@G5W2715.americas.hpqcorp.net> |
--_000_716D07F3CBA94244A0922E7A99837C3A109FBAE4G5W2715americas_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Dennis, Yes - this looks to be the best option. (It's java but it offers the same p= ossibility). So, it's quite a bit more manual work with the Eclipse refactoring tool - b= ut it works. I have to extract the interface of A, then manually inherit from it in IB. And it's a big legacy project with lots of deep inheritance - but, at least= it's clean and doesn't disturb the codebase too much. John D. From: [email protected] [mailto:[email protected]] On B= ehalf Of Dennis Traub Sent: 21 September 2013 11:20 To: [email protected] Subject: Re: [refactoring] how to: extract interface of class with methods = from a superclass Depending on the language you can have an interface inherit from another on= e. Example in C#: public interface IA { void SomeMethodForA(); } public interface IB : IA { void SomeMethodForB(); } public class B : IB { public void SomeMethodForA() { ... } public void SomeMethodForB() { ... } } On Sat, Sep 21, 2013 at 11:11 AM, Donaldson, John <[email protected]<= mailto:[email protected]>> wrote: Michal, Well, yes - any user of B sees A's methods. But when you "extract interface= " you are doing to get the interface to that class - not its supertypes. You should extract the interface of A (IA, which will be implemented by A).= Likewise B should implement the interface to B (IB). So, I can do that and implement two test classes TestA and TestB which impl= ement IA and IB. And I can arrange that TestB inherits TestA. But my original class C imports interface IB (replacing B) - so I don't hav= e the method on IA. It's not at clear how to refactor this without some really invasive modific= ations - which I'd like to avoid! So, the original question stands . what's the good way? John D. -----Original Message----- From: [email protected]<mailto:[email protected]> [mail= to:[email protected]<mailto:[email protected]>] On Beha= lf Of Michal Svoboda Sent: 20 September 2013 20:19 To: [email protected]<mailto:[email protected]> Subject: Re: [refactoring] how to: extract interface of class with methods = from a superclass Donaldson, John wrote: > Except, class B inherits class A and C is calling one of the inherited > methods. > > Quite rightly "extract interface" on B only gives me the methods on B. If B inherits A then interface of B should contain also interface of A. Perhaps only some autonomous extract interface tool doesn't see it? ------------------------------------ Yahoo! Groups Links --_000_716D07F3CBA94244A0922E7A99837C3A109FBAE4G5W2715americas_ Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: 7bit <head> <style type="text/css"> <!-- /* start of attachment style */ .ygrp-photo-title{ clear: both; font-size: smaller; height: 15px; overflow: hidden; text-align: center; width: 75px; } div.ygrp-photo{ background-position: center; background-repeat: no-repeat; background-color: white; border: 1px solid black; height: 62px; width: 62px; } div.photo-title a, div.photo-title a:active, div.photo-title a:hover, div.photo-title a:visited { text-decoration: none; } div.attach-table div.attach-row { clear: both; } div.attach-table div.attach-row div { float: left; /* margin: 2px;*/ } p { clear: both; padding: 15px 0 3px 0; overflow: hidden; } div.ygrp-file { width: 30px; valign: middle; } div.attach-table div.attach-row div div a { text-decoration: none; } div.attach-table div.attach-row div div span { font-weight: normal; } div.ygrp-file-title { font-weight: bold; } /* end of attachment style */ --> </style> </head> <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> <meta name="Generator" content="Microsoft Word 14 (filtered medium)"> <!--[if !mso]><style>v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style><![endif]--><style><!-- /* Font Definitions */ @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman","serif";} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {mso-style-priority:99; color:purple; text-decoration:underline;} p {mso-style-priority:99; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; font-size:12.0pt; font-family:"Times New Roman","serif";} p.ygrp-photo-title, li.ygrp-photo-title, div.ygrp-photo-title {mso-style-name:ygrp-photo-title; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; text-align:center; font-size:10.0pt; font-family:"Times New Roman","serif";} p.ad, li.ad, div.ad {mso-style-name:ad; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; font-size:12.0pt; font-family:"Times New Roman","serif";} p.ad1, li.ad1, div.ad1 {mso-style-name:ad1; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; font-size:12.0pt; font-family:"Times New Roman","serif";} span.EmailStyle21 {mso-style-type:personal-reply; font-family:"Calibri","sans-serif"; color:#1F497D;} .MsoChpDefault {mso-style-type:export-only; font-size:10.0pt;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 72.0pt 72.0pt 72.0pt;} div.WordSection1 {page:WordSection1;} --></style><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1" /> </o:shapelayout></xml><![endif]--> </head> <body lang="EN-US" link="blue" vlink="purple"> <!-- |**|begin egp html banner|**| --> <br><br> <!-- |**|end egp html banner|**| --> <div class="WordSection1"> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Dennis,<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Yes – this looks to be the best option. (It’s java but it offers the same possibility).<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">So, it’s quite a bit more manual work with the Eclipse refactoring tool – but it works.<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I have to extract the interface of A, then manually inherit from it in IB. <o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">And it’s a big legacy project with lots of deep inheritance – but, at least it’s clean and doesn’t disturb the codebase too much.<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">John D.<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p> <div> <div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm"> <p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> [email protected] [mailto:[email protected]] <b>On Behalf Of </b>Dennis Traub<br> <b>Sent:</b> 21 September 2013 11:20<br> <b>To:</b> [email protected]<br> <b>Subject:</b> Re: [refactoring] how to: extract interface of class with methods from a superclass<o:p></o:p></span></p> </div> </div> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><br> <br> <br> <o:p></o:p></p> <div> <p class="MsoNormal">Depending on the language you can have an interface inherit from another one. Example in C#:<o:p></o:p></p> <div> <p class="MsoNormal"><o:p> </o:p></p> </div> <div> <p class="MsoNormal">public interface IA {<o:p></o:p></p> </div> <div> <p class="MsoNormal"> void SomeMethodForA();<o:p></o:p></p> </div> <div> <p class="MsoNormal">}<o:p></o:p></p> </div> <div> <p class="MsoNormal"><o:p> </o:p></p> </div> <div> <p class="MsoNormal">public interface IB : IA {<o:p></o:p></p> </div> <div> <p class="MsoNormal"> void SomeMethodForB();<o:p></o:p></p> </div> <div> <p class="MsoNormal">}<o:p></o:p></p> </div> <div> <p class="MsoNormal"><o:p> </o:p></p> </div> <div> <p class="MsoNormal">public class B : IB {<o:p></o:p></p> </div> <div> <p class="MsoNormal"> public void SomeMethodForA() { ... }<o:p></o:p></p> </div> <div> <p class="MsoNormal"> public void SomeMethodForB() { ... }<o:p></o:p></p> </div> <div> <p class="MsoNormal">}<o:p></o:p></p> </div> </div> <div> <p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p> <div> <p class="MsoNormal">On Sat, Sep 21, 2013 at 11:11 AM, Donaldson, John <<a href="mailto:[email protected]" target="_blank">[email protected]</a>> wrote:<o:p></o:p></p> <div> <p class="MsoNormal"> <o:p></o:p></p> <div> <div> <div> <p>Michal, <br> <br> Well, yes - any user of B sees A's methods. But when you "extract interface" you are doing to get the interface to that class - not its supertypes. <br> You should extract the interface of A (IA, which will be implemented by A). Likewise B should implement the interface to B (IB). <br> <br> So, I can do that and implement two test classes TestA and TestB which implement IA and IB. <br> And I can arrange that TestB inherits TestA. <br> <br> But my original class C imports interface IB (replacing B) - so I don't have the method on IA. <br> It's not at clear how to refactor this without some really invasive modifications - which I'd like to avoid! <br> <br> So, the original question stands . what's the good way? <br> <br> John D. <o:p></o:p></p> <div> <p class="MsoNormal" style="margin-bottom:12.0pt"><br> -----Original Message----- <br> From: <a href="mailto:[email protected]" target="_blank">[email protected]</a> [mailto:<a href="mailto:[email protected]" target="_blank">[email protected]</a>] On Behalf Of Michal Svoboda <br> Sent: 20 September 2013 20:19 <br> To: <a href="mailto:[email protected]" target="_blank">[email protected]</a> <br> Subject: Re: [refactoring] how to: extract interface of class with methods from a superclass <br> <br> Donaldson, John wrote: <br> > Except, class B inherits class A and C is calling one of the inherited <br> > methods. <br> > <br> > Quite rightly "extract interface" on B only gives me the methods on B. <br> <br> If B inherits A then interface of B should contain also interface of A. <br> Perhaps only some autonomous extract interface tool doesn't see it? <br> <br> <br> <o:p></o:p></p> </div> <p class="MsoNormal" style="margin-bottom:12.0pt">------------------------------------ <br> <br> Yahoo! Groups Links <br> <br> <br> <o:p></o:p></p> </div> </div> </div> </div> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><br> <br> <br> <o:p></o:p></p> <div> <p class="MsoNormal"><span style="color:white"><o:p></o:p></span></p> </div> </div> </div> </div> <!-- |**|begin egp html banner|**| --> <br> <br> <!-- |**|end egp html banner|**| --> <div width="1" style="color: white; clear: both;"/>__._,_.___</div> <!-- Start Recommendations --> <!-- End Recommendations --> <!-- |**|begin egp html banner|**| --> <img src="http://geo.yahoo.com/serv?s=97476590/grpId=3975602/grpspId=1707276718/msgId=10699/stime=1379919923" width="1" height="1"> <br> <!-- |**|end egp html banner|**| --> <!-- |**|begin egp html banner|**| --> <br> <div style="font-family: verdana; font-size: 77%; border-top: 1px solid #666; padding: 5px 0;" > Your email settings: Individual Email|Traditional <br> <a href="http://groups.yahoo.com/group/refactoring/join;_ylc=X3oDMTJmaW1mc3NwBF9TAzk3NDc2NTkwBGdycElkAzM5NzU2MDIEZ3Jwc3BJZAMxNzA3Mjc2NzE4BHNlYwNmdHIEc2xrA3N0bmdzBHN0aW1lAzEzNzk5MTk5MjM-">Change settings via the Web</a> (Yahoo! ID required) <br> Change settings via email: <a href="mailto:[email protected]?subject=Email Delivery: Digest">Switch delivery to Daily Digest</a> | <a href = "mailto:[email protected]?subject=Change Delivery Format: Fully Featured">Switch to Fully Featured</a> <br> <a href="http://groups.yahoo.com/group/refactoring;_ylc=X3oDMTJkcDQ4azA1BF9TAzk3NDc2NTkwBGdycElkAzM5NzU2MDIEZ3Jwc3BJZAMxNzA3Mjc2NzE4BHNlYwNmdHIEc2xrA2hwZgRzdGltZQMxMzc5OTE5OTIz"> Visit Your Group </a> | <a href="http://info.yahoo.com/legal/us/yahoo/utos/terms/"> Yahoo! Groups Terms of Use </a> | <a href="mailto:[email protected]?subject=Unsubscribe"> Unsubscribe </a> <br> </div> <br> <!-- |**|end egp html banner|**| --> <div style="color: white; clear: both;"/>__,_._,___</div> </body> </html> --_000_716D07F3CBA94244A0922E7A99837C3A109FBAE4G5W2715americas_--