answersLogoWhite

0

Message to method binding

A question of whether a message should bind to

  • a method in the class to which the reference variable pointing to the receiver was declared to be an instance of (static binding), or
  • a method in the class to which the receiver is an instance of at run-time (dynamic binding).
Dynamic binding
  • in the context of OOP typically refers to the binding of methods to messages
  • methods varying dynamically entails much of the power of the OO approach
  • main source of power in an OO language
  • search for method (code body) to bind to a message starts from the class to which the receiver currently (i.e., at run-time) is an instance of, and and proceeds up the class inheritance hierarchy from there (static binding initiates the search from the class to which the reference variable pointing to the receiver was declared to be an instance of)
  • if no method found anywhere, a run-time error (method not found) is reported and this is typically the only error in a Smalltalk program ever detected and reported
  • example: Mammal m; Cow c; if (user input) m = new Cow; // if static binding used, run method in class Mammal bound to run message here // if dynamic binding used, run method in class Cow bound to run message here m.run else c = new Cow; c.run
Why dynamic binding?
  • `to allow software systems to be more easily extended during both development and maintenance' [COPL] p. 461
  • allows dynamic polymorphism, consider sorting (written in a general way)
  • obviates need for abstract classes (e.g., Fruit class, peel method)
  • while other forms of dynamism in languages tend to be compromise efficiency in the run-time system, dynamic binding involves little overhead
Dynamic vs. static binding
  • advantages of each?
  • disadvantages of each?
Message to method binding in languages
  • Smalltalk
    • dynamic by default
    • by sending a message to super we can initiate the search (for the method to bind to the message) in the parent class of the class to which the sender belongs (i.e., like sending a message to self with a different entry point for the search (not quite static binding))
  • Java and Eiffel
    • dynamic by default
    • in Java, preface method with final qualifier to prevent any subclass from overriding it
    • in Eiffel, preface method with frozen qualifier to prevent any subclass from overriding it
  • C++
    • static by default (why?)
    • preface method with virtual qualifier for dynamic binding; the search for the method to bind to the message starts in the class which defines the method prefaced with the virtual qualifier and proceeds down the inheritance hierarchy from there to the class to which the receiver object belongs
  • Objective-C, Modula-3, Python, and Ruby use dynamic binding for all methods
  • Simula, C# and Ada 95 use static binding by default and support dynamic binding as an option
Dynamic binding ambiguity

Do not confuse dynamic binding of messages to methods with dynamic allocation and deallocations of objects.

  • Smalltalk: manual dynamic allocation, automatic deallocation
  • Java: manual dynamic allocation, automatic deallocation
  • C++: manual dynamic allocation, manual deallocation
User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

What is the difference between signal and event?

The main different between a traditional signal and a message is their recipient. A signal is often sent to a mass of people, while a message is more individualized.


Difference between HTML and dhtml - point wise?

Dynamic HTML is basically using HTML and some other things to enhance it, usually Javascript and Styles. All HTML really does is format your page. To get your page to do things, you need more than just plain HTML. The following code will create a button that you can click on and it will pop up a message. It uses Javascript. Copy and paste it or type it exactly as it is into your code and it will work.The onClick="alert('Hello');" piece is Javascript. Without it you would still have the button, but when it was clicked, it would not do anything. The Javascript makes your page come alive as it were. That is the idea of Dynamic HTML.


What is message passing explain the advantages of message passing?

message passing is the way of exchanging information between systems or individuals,at d same time.advantage is that we can interact by getting all the necessary details


Functionalities in difference between Shared Memory and Message Queue?

SHM:it's an area of storage that can be read and written by more than one process.MSGQ:A message queue is like a pipe,by using more comprehensive mechanism we can read message from both end.SHM:It provides no inherent synchronizationMSGQ:It provides inherent synchronization,So the writer can never fail after writing only a partial message, and the reader will either retrieve a complete message or nothing at all.SHM:possiblity of occuring race condition.MSGQ: No race conditon actually occure.SHM: fasterMSGQ:slower than shared memory


What are the oops concepts in net?

the 4 oops concept are: 1. Encapsulation: The process of wrapping data into a single unit is called Encapsulation 2. Inheritance: This the process in which a properties of a predefined class can be inherited in a new class making the object of that class in the making class. 3. Polymorphism: This the process in which a program can have more than one function with the same name but different parameters. 4. Data Hiding: It is the process of creating a logical insulation between the program and the environment.

Related Questions

What are the differences between dynamic binding and message passing?

It seems to me that the two are completely unrelated, so I don't see a reason to try to compare them.


What is the difference between a channel and a medium in communication?

the difference between channel and medium is that channel is the form how the message will be while medium is the actual message


Is it possible for a text message to be legally binding?

Yes, a text message can be legally binding if it meets the requirements for a contract, such as offer, acceptance, and consideration, and if both parties intend for it to be legally binding.


What is the difference between telegram and a letter?

The difference between a telegram and a telegraph is that a telegram is a message communicated through delivered in written or printed message from while a letter is written or printed message usually in envelop sent by post.


Difference between queued messages and non queued messages?

queued message are system defined message and nonqueed message are applicaton defined message.


In British law is a text message legally binding?

There is no reason why a text message 'contract' should not be legally binding, however there have not been any precedent setting cases on the issue.


What is the difference between message and message?

massage is a word or phrase that is sent. a massage is also a action of rubbing and caressing the body for relaxation


What is the difference between manner and matter?

I also left you a voice message in regard to this manner.


Is a text message legally binding in California?

Yes, a text message can be legally binding in California if it meets the requirements for a valid contract, such as offer, acceptance, and consideration. It is important to carefully consider the content and context of the text message to determine its legal implications.


Does a text message count as a legal agreement?

No, a text message alone typically does not constitute a legally binding agreement.


What is the difference between an academic paper and a business document?

less importnt to the message of a business document but more important to the message of academic paper.


What message did the Gettysburg address communicate to the war-torn nation in1863?

That there is no difference between man.