Re: how to: extract interface of class with methods from a superclass
Dennis Traub <[email protected]> Sat, 21 Sep 2013 11:20:22 +0200
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <CAJw46f7wj87TYfVCZpeDoDEJRvxctgB_iix5-0SNsDxnZPe9Ng@mail.gmail.com> |
--089e01681f7eecfe0f04e6e14b29
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
Depending on the language you can have an interface inherit from another
on=
e. Example in C#:
public interface IA {
void SomeMethodForA();
}
publ=
ic 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
<john.m.donald=
[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 inte=
rface to that class - not its
> supertypes.
> You should extract the interf=
ace of A (IA, which will be implemented by
> A). Likewise B should implemen=
t the interface to B (IB).
>
> So, I can do that and implement two test cla=
sses TestA and TestB which
> implement IA and IB.
> And I can arrange that =
TestB inherits TestA.
>
> But my original class C imports interface IB (rep=
lacing B) - so I don't
> have the method on IA.
> It's not at clear how to =
refactor this without some really invasive
> modifications - 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]] On
> Behalf Of Michal Svoboda
> Sent: =
20 September 2013 20:19
> To: [email protected]
> Subject: Re: [r=
efactoring] how to: extract interface of class with methods
> from a superc=
lass
>
> 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 i=
nterface of B should contain also interface of A.
> Perhaps only some auton=
omous extract interface tool doesn't see it?
>
>
>
> ----------------------=
--------------
>
> Yahoo! Groups Links
>
>
>
>
>
--089e01681f7eecfe0f04e6e14b29
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
<head>
<style type=3D"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=20
a,
div.photo-title a:active,
div.photo-title a:hover,
div.photo-title a:visited {
text-decoration: none;=20
}
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>
<head>
<style type=3D"text/css">
<!--
#ygrp-mkp {
border: 1px solid #d8d8d8;
font-family: Arial;
margin: 10px 0;
padding: 0 10px;
}
#ygrp-mkp hr {
border: 1px solid #d8d8d8;
}
#ygrp-mkp #hd {
color: #628c2a;
font-size: 85%;
font-weight: 700;
line-height: 122%;
margin: 10px 0;
}
#ygrp-mkp #ads {
margin-bottom: 10px;
}
#ygrp-mkp .ad {
padding: 0 0;
}
#ygrp-mkp .ad p {
margin: 0;
}
#ygrp-mkp .ad a {
color: #0000ff;
text-decoration: none;
}
-->
</style>
</head>
<body>
<!-- |**|begin egp html banner|**| -->
<br><br>
<!-- |**|end egp html banner|**| -->
<div dir=3D"ltr">Depending on the language you can have an interface inheri=
t from another one. Example in C#:<div><br></div><div>public interface IA {=
</div><div>=A0 =A0 void SomeMethodForA();</div><div>}</div><div><br></div><=
div>
public interface IB : IA {</div><div>=A0 =A0 void SomeMethodForB();</div><d=
iv>}</div><div><br></div><div>public class B : IB {</div><div>=A0 =A0 publi=
c void SomeMethodForA() { ... }</div><div>=A0 =A0 public void SomeMethodFor=
B() { ... }</div>
<div>}</div></div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_qu=
ote">On Sat, Sep 21, 2013 at 11:11 AM, Donaldson, John <span dir=3D"ltr">&l=
t;<a href=3D"mailto:[email protected]" target=3D"_blank">john.m.donal=
[email protected]</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">
<u></u>
<div style>
<span>=A0</span>
<div>
<div>
<div>
=20=20=20=20=20=20
=20=20=20=20=20=20
<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 impl=
ement 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 mod=
ifications - which I'd like to avoid!
<br>
<br>
So, the original question stands . what's the good way?
<br>
<br>
John D.
<br></p><div class=3D"im">
<br>
-----Original Message-----
<br>
From: <a href=3D"mailto:[email protected]" target=3D"_blank">refa=
[email protected]</a> [mailto:<a href=3D"mailto:refactoring@yahoogrou=
ps.com" target=3D"_blank">[email protected]</a>] On Behalf Of Mic=
hal Svoboda
<br>
Sent: 20 September 2013 20:19
<br>
To: <a href=3D"mailto:[email protected]" target=3D"_blank">refact=
[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=
=20
<br>
> methods.
<br>
>=20
<br>
> Quite rightly "extract interface" on B only gives me the met=
hods 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>
<br></div>
------------------------------------
<br>
<br>
Yahoo! Groups Links
<br>
<br>
<br>
<br>
<p></p>
</div>
=20=20=20=20=20
=20=20=20=20
<div style=3D"color:#fff;min-height:0"></div>
</div>
=20=20
</blockquote></div><br></div>
<!-- |**|begin egp html banner|**| -->
<br>
<br>
<!-- |**|end egp html banner|**| -->
<div width=3D"1" style=3D"color: white; clear: both;"/>__._,_.___</div>
=20=20=20=20=20=20
=20=20=20=20=20=20
<!-- Start Recommendations -->
<!-- End Recommendations -->
<!-- |**|begin egp html banner|**| -->
<img src=3D"http://geo.yahoo.com/serv?s=3D97476590/grpId=3D3975602/grpspI=
d=3D1707276718/msgId=3D10697/stime=3D1379777040" width=3D"1" height=3D"1"> =
<br>
<!-- |**|end egp html banner|**| -->
=20=20
<!-- |**|begin egp html banner|**| -->
<br>
<div style=3D"font-family: verdana; font-size: 77%; border-top: 1px s=
olid #666; padding: 5px 0;" >
Your email settings: Individual Email|Traditional <br>
<a href=3D"http://groups.yahoo.com/group/refactoring/join;_ylc=3DX3oD=
MTJmN2J2NWNsBF9TAzk3NDc2NTkwBGdycElkAzM5NzU2MDIEZ3Jwc3BJZAMxNzA3Mjc2NzE4BHN=
lYwNmdHIEc2xrA3N0bmdzBHN0aW1lAzEzNzk3NzcwNDA-">Change settings via the Web<=
/a> (Yahoo! ID required) <br>
Change settings via email: <a href=3D"mailto:refactoring-digest@yahoo=
groups.com?subject=3DEmail Delivery: Digest">Switch delivery to Daily Diges=
t</a> | <a href =3D "mailto:[email protected]?subjec=
t=3DChange Delivery Format: Fully Featured">Switch to Fully Featured</a> <b=
r>
<a href=3D"http://groups.yahoo.com/group/refactoring;_ylc=3DX3oD=
MTJkam4yY21pBF9TAzk3NDc2NTkwBGdycElkAzM5NzU2MDIEZ3Jwc3BJZAMxNzA3Mjc2NzE4BHN=
lYwNmdHIEc2xrA2hwZgRzdGltZQMxMzc5Nzc3MDQw">
Visit Your Group=20
</a> |
<a href=3D"http://info.yahoo.com/legal/us/yahoo/utos/terms/">
Yahoo! Groups Terms of Use
</a> |
<a href=3D"mailto:[email protected]?subject=3DU=
nsubscribe">
Unsubscribe=20
</a>=20
<br>
</div>
<br>
<!-- |**|end egp html banner|**| -->
<div style=3D"color: white; clear: both;"/>__,_._,___</div>
</body>
</html>
--089e01681f7eecfe0f04e6e14b29--