Objective-C가 진정한 동적 바인딩을 가지고있는 모든 곳을 읽었습니다. C++에는 Late 바인딩 만 있습니다. 불행히도 그 책을 명확하게 설명하거나 기본 구현을 논의하기위한 책은 없습니다. 예를 들어, C++은 가상 테이블을 사용합니다. Objective-C는 어떻습니까?Late Binding vs Dynamic Binding
답변
http://www.gnu.org/software/gnustep/resources/ObjCFun.html은 꽤 좋은 설명이 있습니다.
기본적으로 동적 바인딩은 메서드 호출이 실제로 만들어 질 때 호출 할 메서드가 결정된다는 것을 의미합니다. 그리고 그 방법은, 원한다면, 그 시점에서 동적으로 선택 될 수 있습니다.
편집 : 여기 내 이해를위한 세부 정보가 많이 있습니다. 나는 이것이 완전히 정확하다고 약속하지는 않지만 대부분 옳을 것이다. Objective C의 모든 객체는 구조체이며 첫 번째 멤버 인 isa
은 클래스에 대한 포인터입니다. 여기, 런타임시
struct objc_class {
Class isa;
Class super_class;
const char *name;
long version;
long info;
long instance_size;
struct objc_ivar_list *ivars;
struct objc_method_list **methodLists;
struct objc_cache *cache;
struct objc_protocol_list *protocols;
};
의사 코드는 방법 조회에 무슨입니다 : 각 클래스 자체는 전통적으로 배치되는 개체입니다
Follow isa to find the class
if implementation = class.lookup_method(method):
call implementation
else if get_implementation = class.lookup_method(forwardInvocation):
implementation = get_implementation(method)
if implementation:
call implementation
else:
raise runtime error
else:
raise runtime error
그리고 어떻게 lookup_method
작동합니까?
def lookup_method (class, method):
if method in class.objc_cache:
return implementation from objc_cache
else if method in class.objc_method_list:
cache implementation from objc_method_list
return implementation
else if implementation = class.super_class.lookup_method(method):
cache implementation
return implementation
else:
return null
확실한 질문에 대한 대답으로 예, 이것은 C++의 가상 테이블보다 훨씬 느립니다. 벤치 마크에 따르면 속도의 1/3 정도입니다. 모든 Objective C 텍스트는 실제 세계에서 메서드 검색 속도가 거의 병목 현상이 아니므로 바로 뒤 따릅니다.
이것은 C의 메소드 검색보다 훨씬 융통성이 있습니다. 예를 들어 forwardInvocation
을 사용하면 인식 할 수없는 메서드가 변수에있는 객체로 이동합니다. 이러한 유형의 위임은 런타임에 해당 개체의 형식이 무엇인지 또는 어떤 방법을 지원하는지 모른 채 수행 될 수 있습니다. 원할 경우 런타임에서도 소스 코드에 액세스 할 필요없이 클래스에 메서드를 추가 할 수 있습니다. 또한 클래스와 메소드에 대해 풍부한 런타임 내부 검사 기능을 제공합니다.
모든 C++ 프로그래머가 위아래로 뛰어 오를 것이라는 명백한 측면은 컴파일 유형 검사의 희망을 버린 것입니다.
차이점을 설명하고 진행 상황을 이해하기에 충분한 세부 정보를 제공합니까?
동적 바인딩과 후기 바인딩 모두 사실입니다. 우리는 정적 바인딩, 또는 초기 바인딩, 컴파일 타임에 일어나는 문제 (thevariables, 식에 관한 오류 등) 및 이러한 정보는 v 테이블 (가상 메서드 테이블)에 저장되어 있는지 확인합니다. 늦은 바인딩은 v-table에있는 메소드와 메소드를 바인드하는 것입니다.
- 1. JGoodies Binding vs. JSR 295
- 2. "{Binding Path =.}"및 "{Binding}"은 실제로 동일합니다
- 3. Asp.Net binding
- 4. DataGridViewComboBoxColumn Binding
- 5. Silverlight Binding
- 6. Silverlight DataGrid 및 Binding 열
- 7. {Binding PropertyName}과 {Binding Path = PropertyName}의 차이점
- 8. WPF ComboBox Binding 바꾸기
- 9. JQuery DatePicker Binding
- 10. MVVM Combobox binding
- 11. wpf/silverlight binding help
- 12. Silverlight4 net.tcp binding
- 13. 난이도 : RadCombobox ItemsSource Binding
- 14. Binding conveter에 논리가 없습니다
- 15. WPF ListBox Aynchronous Binding
- 16. WPF Binding RelativeSource 문제
- 17. "{Binding RelativeSource = {RelativeSource FindAncestor
- 18. WPF ItemsSource Binding
- 19. WPF Shape Rectangle Binding
- 20. Spring 3 Collection Binding
- 21. WPFtoolkit Chart, Object Binding
- 22. WPF Binding XML List
- 23. WCF Service Binding
- 24. MVC2 ViewModel Binding
- 25. WPF binding Ancestor
- 26. Xaml : Itemssource binding + fallbackValue
- 27. ListBox SelectedItems Binding
- 28. Ninject convention based binding
- 29. Silverlight RadDataPager Binding
- 30. XAML ListBox Binding
예를 들려 줄 수 있습니까? 귀하의 대답은 모든 교과서만큼 모호합니다. –
@ vinod-james : 사용 된 실제 메커니즘에 대한 많은 세부 사항을 추가했습니다. – btilly