Reintroduce/fi: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Reintroduce/fi
| Old | New | Line | |
|---|---|---|---|
| 1 | + | Määritettä ([[modifier/fi|modifier]]) `reintroduce` käytetään [[object-oriented programming/fi|olio-ohjelmoinnissa]]. Määrite `reintroduce` mahdollistaa vanhemman (kanta) [[Class|luokan]] [[Method|metodin]] piilottamisen uudella metodilla, jolla on sama nimi. Toisin sanoen luokassa on nyt uusi metodi, joka on peräisin tästä luokassa. Vanhemman luokan metodi säilyy ja sitä voi silti käyttää. | |
| 2 | + | ||
| 3 | + | Kantaluokan metodia ei enää ole olemassa uudessa luokassa, vaan se on korvattu uudella metodilla, jolla on sama nimi. Metodi säilyy alkuperäisessä muodossa vanhemmassa luokassa ja sitä voidaan käyttää vanhemman luokan kautta. | |
| 4 | + | ||
| 5 | + | Esimerkki: | |
| 6 | + | ||
| 7 | + | ``` pascal | |
| 8 | + | interface | |
| 9 | + | ||
| 10 | + | type | |
| 11 | + | TParentClass = class | |
| 12 | + | procedure SetTest(intNum: Integer); // Jokin metodi | |
| 13 | + | end; | |
| 14 | + | ||
| 15 | + | TDerivedClass = class(TParentClass) | |
| 16 | + | procedure SetTest(strName: String); reintroduce; // Tämä korvaa vanhemman luokan metodin. | |
| 17 | + | end; | |
| 18 | + | ||
| 19 | + | implementation | |
| 20 | + | ||
| 21 | + | procedure TDerivedClass.SetTest(strName: String); | |
| 22 | + | begin | |
| 23 | + | inherited SetTest(1); // kutsutaan samalla nimellä vanhemman luokan metodia tarvittaessa | |
| 24 | + | end; | |
| 25 | + | ``` | |
| 26 | + | ||
| 27 | + | --- | |
| 28 | + | *From the Free Pascal wiki, page "Reintroduce/fi", as it stood on 2019-11-10 after a change by Djzepi, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
