dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.24k stars 5.88k forks source link

Early & Late Binding Definition needs more clarity #26381

Open sougata12 opened 3 years ago

sougata12 commented 3 years ago

[The definition of late binding as per this page is: an object is late bound when it is assigned to a variable declared to be of type Object. Now this makes one feel that in the following code piece it is the step Dim m as Object = New MathOperations() where late binding happens because this is the step where an object of MathOperations type gets assigned to a variable "m" of object type. PLs refer to the SO link given below to see the full code.

However when I wrote this in SO, it was pointed out that it is the step m.ADD where late binding actually happens which confused me as this was unexpected if one goes strictly by the definition. It was also pointed out that the example that the MSDN documentation currently gives (involving xlApp and CreateObject) is different from the example that I have mentioned just before - the type is unknown in the example that MSDN uses. Now this creates confusion in the minds of a beginner who goes strictly by the definition. Hence I request you to expand the definition and explain both cases so that even a beginner my understand.

Secondly, a SO user also pointed out that Late binding is referring to a property or a method on something of type Object (other than the things that exist on Object themselves like Equals). Now I understand that given that late and early binding is not a binary concept (Eric Lippert has written on it) I do feel that this is the most commonly accepted definition but not the general definition. Would you like to add this point to the SDN page also as it helps the reader understand the difficulty when it comes to defining Late Binding.

Finally, I would also suggest to add a section where you explain the role REFLECTION in late binding.

I request you to refer the following links when you read this:

For the code I posted in SO where the MathOperations Class is defined. Requesting your attention to the comments by Craig, Jimi and my responses to them. https://stackoverflow.com/questions/69416063/unable-to-understand-why-compiler-asking-for-reference-to-a-class-library-even-i?noredirect=1#comment122730570_69416063

Eric Lippert's articles where he discusses the difficulty in defining Late Binding: [https://ericlippert.com/2012/02/06/what-is-late-binding/#more-2124] & [https://stackoverflow.com/questions/8410308/is-boxing-unboxing-implemented-through-late-or-early-bindingie-at-runtime-or-c] Firstly,

]


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

BillWagner commented 3 years ago

Thanks for noting all this @sougata12

I've added this to our backlog for when we next update this article