Hejto.pl
Dodaj post

Wpisz coś do wyszukania (minimum 2 znaki)

Wpis użytkownika hapaczuri w Programowanie

Kosmonauta

w Programowanie

1piorunów

Jeśli klasa implementuje interfejs, który zawiera sam nagłówek metody, której klasa nadaje implementację, to czy jest to przykład przesłonięcia?

Komentarze (8)

Tytan1piorunów

@hapaczuri Nie. Przesłonięcie polega na tym że w lokalnej przestrzeni nazw jedna nazwa przesłania inną. Tutaj obie nazwy (Interfejs.metoda i Klasa.metoda) są dalej widoczne tak jak były.

Tytan0piorunów

Dla czytających później: jednak opowi chodziło o coś innego niż "variable shadowing"

CC: @LondoMollari

Kosmonauta3piorunów

@hapaczuri a można po angielsku? Co to jest przesłonięcie? Chodzi o method override?

Tytan1piorunów

@hapaczuri o matko, zakładałem że mówisz o tym: https://pl.m.wikipedia.org/wiki/Przes%C5%82anianie ; D

Serio, IT jest po angielsku, wywalam angielszczyzny skąd się da, ale nie w języku branżowym, właśnie z powodu powyższego.

W takim razie odpowiedź brzmi: Tak. To jest klasyczny polimorfizm dynamiczny.

Przes%C5%82anianieWikipedia
Tytan1piorunów

@globalbus Zakładam że OPowi chodzi o https://en.wikipedia.org/wiki/Variable_shadowing

Variable shadowingIn computer programming, variable shadowing occurs when a variable declared within a certain scope (decision block, method, or inner class) has the same name as a variable declared in an outer scope. At the level of identifiers (names, rather than variables), this is known as name masking. This outer variable is said to be shadowed by the inner variable, while the inner identifier is said to mask the outer identifier. This can lead to confusion, as it may be unclear which variable subsequent uses of the shadowed variable name refer to, which depends on the name resolution rules of the language. One of the first languages to introduce variable shadowing was ALGOL, which first introduced blocks to establish scopes. It was also permitted by many of the derivative programming languages including C, C++ and Java. The C# language breaks this tradition, allowing variable shadowing between an inner and an outer class, and between a method and its containing class...Wikipedia
Osobistość0piorunów

@hapaczuri Moim zdaniem jeżeli interface nie ma domyślnej implementacji metody, to nie zachodzi przesłonięcie - bo jakby nie patrzeć nie ma implementacji, którą możesz przesłaniać - jeżeli jej nie zaimplementujesz, to się wy⁎⁎⁎ie :smiley: Nie można przesłonić czegoś, czego nie ma.
A z drugiej strony dodaje się @Override ¯\\( ͡° ͜ʖ ͡°)

Edit. po poniższych odpowiedziach, chyba nieprawidłowo zrozumiałem pytanie :smiley: