Uas Keamanan Informasi

Kata kriptografi atau cryptography diketahui berasal dari bahasa Yunani, kripto dan graphia. Dimana kripto memiliki arti menyembunyikan, sementar graphia berarti tulisan. Sehingga bisa dijabarkan…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Early vs. Late Binding at the Chinese Restaurant

In this continuation of our Chinese restaurant-COM metaphor, we expand the example to illustrate the differences between early and late binding.

A programming object written in one language (say, C++) can be called from a different language (say, VBA) because the two languages agree on a common interface. VBA can call the functions in the C++ object one of two basic ways:

Let’s expand the Chinese restaurant metaphor to illustrate these two approaches.

In our scenario, the customer speaks only English while the chef speaks mostly Chinese, but does understand English numbers.

How do these two communicate? First, the chef puts together a numbered menu with meal descriptions in both Chinese and English. With a copy of the menu, the customer tells the chef the number of her selection (“number 5”… the chicken lo mein).

The chef hears number 5, checks his menu for the Chinese description, and prepares the meal. Very efficient.

This approach only works if the customer has a copy of the menu.

In VBA, the menu corresponds to a COM object’s type library, which gets incorporated at runtime via the Tools > References… dialog. Of course, this only works if both the customer and the chef are using the same menu. My menu from the Great Wall Restaurant says that chicken lo mein is #5. But if I call China Palace instead of Great Wall and order a #5, I could end up with shrimp fried rice.

It’s very important that the type library on the development computer is identical (or at least binary compatible) with the COM object on the end user’s computer.

What if I was visiting a new city and I didn’t have a menu for the local Chinese place?

I call up the restaurant to place my order. I can’t provide them with a number for my order because I don’t have the menu. Instead, I order by name. Luckily, the employee who answers the phone is bilingual. I tell her I want the chicken lo mein. She translates my order into Chinese as she passes it along to the chef.

Being able to order by name gives me some flexibility. I don’t have to limit myself to only those Chinese restaurants for which I already have a menu. I could call any restaurant so long as it could serve me “chicken lo mein.”

Notice that in this scenario there was no guarantee that the restaurant I called even served chicken lo mein. In other words, there was no compile-time checking. If my order failed, I would not know until runtime (i.e., while I was on the phone ordering).

It’s important to note that ordering my meal by name was only an option because the Chinese restaurant had a bilingual employee answering the phone.

There’s no real way to know from VBA whether a given COM object supports late-binding. You would need to have access to the COM object’s source code to know for sure. Lacking that, you have to rely on either the COM object’s documentation or trial and error.

Just know that some COM objects do not support late binding.

A COM object that supports both early binding and late binding is said to have dual interfaces.

Add a comment

Related posts:

Welcome to Your Local Real Estate Update Center

The real estate market is where people begin and continue their lives. Many buy and live in homes for shelter, while some buy and sell homes for investments. Either purpose requires constant…

O que um bom Product Owner faz?

Escrever sobre Product Owner não é fácil, é um dos papeis mais importante dentro de um Time, tão importante que irei destacar desdo começo desse artigo a seguinte frase: Falando sobre as regras de…

Masyarakat Demokratis Tanpa Teror

Dalam masyarakat demokratis, kebebasan mengekspresikan pandangan politik adalah niscaya. Namun, ini pula yang menjadi celah bagi tumbuhnya radikalisme dan terorisme. Mengatasinya, negara menjadi…