Ruby/Kontrola dostępu: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
Kj (dyskusja | edycje)
m +nav
Szymon wro (dyskusja | edycje)
mNie podano opisu zmian
Linia 50:
We might have expected test.engine(6) to return 12, but instead we learn that engine is inaccessible when we are acting as a user of a Test object. Only other Test methods, such as times_two, are allowed to use engine. We are required to go through the public interface, which consists of the times_two method. The programmer who is in charge of this class can change engine freely (here, perhaps by changing b*2 to b+b, assuming for the sake of argument that it improved performance) without affecting how the user interacts with Test objects. This example is of course much too simple to be useful; the benefits of access controls become more clear only when we begin to create more complicated and interesting classes.
<noinclude>
{{ProstaNawigacja|spis=Ruby|poprzart=Ruby/RedefinicjaRedefiniowanie metod|poprz=RedefinicjaRedefiniowanie metod|nastart=Ruby/Metody singleton|nast=Metody sigleton}}
</noinclude>