pascalabcnet/PABCNetHelp/LangGuide/Interfaces/manyinterf.html
Mikhalkovich Stanislav 66b7aa42c5 fix #2058
Небольшие правки в CodeTemplates
2019-08-02 10:17:49 +03:00

56 lines
2.6 KiB
HTML

<html>
<head>
<object type="application/x-oleobject" classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e">
</object>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title></title>
<link rel="StyleSheet" href="../../default.css">
</head>
<body>
<H1>Ðåàëèçàöèÿ íåñêîëüêèõ èíòåðôåéñîâ </H1>
<p>Íåñêîëüêî èíòåðôåéñîâ ìîãóò ñîäåðæàòü îäèíàêîâûå ìåòîäû èëè
ñâîéñòâà. Ïðè íàñëåäîâàíèè îò òàêèõ èíòåðôåéñîâ òàêèå îäèíàêîâûå ìåòîäû èëè
ñâîéñòâà ñëèâàþòñÿ â îäèí:</p>
<blockquote>
<p><code><b>type</b><br>
&nbsp; IShape = <b>interface</b><br>&nbsp;&nbsp;&nbsp;
<b>procedure</b> Draw;<br>&nbsp;&nbsp;&nbsp; <b>property</b> X: integer <b>read</b>;<br>&nbsp;&nbsp;&nbsp;
<b>property</b> Y: integer <b>read</b>;<br>&nbsp;
<b>end</b>;<br>
&nbsp; IBrush = <b>interface</b><br>&nbsp;&nbsp;&nbsp;
<b>procedure</b> Draw;<br>&nbsp;&nbsp;&nbsp; <b>property</b>
Size: integer <b>read</b>;<br>&nbsp;
<b>end</b>;<br>
&nbsp; Brush = <b>class</b>(IShape,IBrush)<br>
&nbsp;&nbsp;&nbsp;
<b>procedure</b> Draw;<br>&nbsp;&nbsp;&nbsp; <strong>begin</strong><br>&nbsp;&nbsp;&nbsp;
<strong>end</strong>;<br>&nbsp; <b>end</b>;</code></p>
</blockquote>
<p>×òîáû ðåøèòü ïðîáëåìó ñ îäèíàêîâûìè èìåíàìè â èíòåðôåéñàõ, â .NET êëàññû
ìîãóò ðåàëèçîâûâàòü ìåòîäû èíòåðôåéñîâ òàê íàçûâàåìûì <strong>ÿâíûì</strong>
îáðàçîì, òàê ÷òî âûçîâ ìåòîäà èíòåðôåéñà äëÿ ïåðåìåííîé êëàññà âîçìîæåí òîëüêî
ïîñëå ÿâíîãî ïðèâåäåíèÿ ê òèïó èíòåðôåéñà. <span id="nsrTitle">Íàïðèìåð:</span></p>
<blockquote>
<p><code><strong>type</strong><br>&nbsp; IWindow = <strong>interface</strong><br>&nbsp;&nbsp;&nbsp;
procedure Menu;<br>&nbsp; <strong>end</strong>;<br>&nbsp; IRestaurant =
<strong>interface</strong><br>&nbsp;&nbsp;&nbsp; procedure Menu;<br>&nbsp;
<strong>end</strong>;<br>&nbsp; RestaurantSystem = <strong>class</strong>(IWindow,IRestaurant)<br>&nbsp;&nbsp;&nbsp;
<strong>public</strong><br>&nbsp;&nbsp;&nbsp; <strong>procedure</strong>
IWindow.Menu; // ÿâíàÿ ðåàëèçàöèÿ ìåòîäà èíòåðôåéñà<br>&nbsp;&nbsp;&nbsp;
<strong>begin</strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Println('IWindow.Menu');<br>&nbsp;&nbsp;&nbsp; <strong>end</strong>;<br>&nbsp;&nbsp;&nbsp;
<strong>procedure</strong> IRestaurant.Menu;<br>&nbsp;&nbsp;&nbsp; <strong>
begin</strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Println('IRestaurant.Menu');<br>&nbsp;&nbsp;&nbsp; <strong>end</strong>;<br>&nbsp;
<strong>end</strong>;<br><br><strong>begin</strong><br>&nbsp; <strong>var</strong>
r := new RestaurantSystem;<br>&nbsp; IWindow(r).Menu; <br>&nbsp;
IRestaurant(r).Menu; <br>&nbsp; r.Menu; // îøèáêà êîìïèëÿöèè!<br><strong>end</strong>. </code>
&nbsp;</p>
</blockquote>
<p>&nbsp;</p>
</body>
</html>