answersLogoWhite

0

If the range of actual types that can be used is finite and the combinations must be specified individually prior to use, it is called ad-hoc polymorphism.

Ad-hoc polymorphism usually refers to simple overloading, but sometimes automatic type conversion, known as coercion, is also considered to be a kind of ad-hoc polymorphism. Common to these two types is the fact that the programmer has to specify exactly what types are to be usable with the polymorphic function.

The name refers to the manner in which this kind of polymorphism is typically introduced: "Oh, hey, let's make the + operator work on strings, too!" Some argue that ad-hoc polymorphism is not polymorphism in a meaningful computer science sense at all---that it is just syntactic sugar for calling append_integer, append_string, etc., manually. One way to see it is that

  • to the user, there appears to be only one function, but one that takes different types of input and is thus type polymorphic; on the other hand,
  • to the author, there are several functions that need to be written---one for each type of input---so there's essentially no polymorphism.

Example

Imagine, if you will, an operator + that may be used in the following ways:

  1. 1 + 2 → 3
  2. 3.14 + 0.0015 → 3.1415
  3. 1 + 3.7 → 4.7
  4. [1, 2, 3] + [4, 5, 6] → [1, 2, 3, 4, 5, 6]
  5. [true, false] + [false, true] → [true, false, false, true]
  6. "foot" + "ball" → "football"
User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Polymorphism in coelentrates?

polymorphism in coelentrates


When was Adhoc Party for PlayStation Portable created?

Adhoc Party for PlayStation Portable was created on 2008-11-06.


How do you get into adhoc on invizimals with a psp e1004?

Because the E1000 PSP has no wireless capabilities it can't go into adhoc mode.


What is the adhoc recruitment?

maika ti


What is polymorphism and its types?

Polymorphism means multiple form of a function, variable or object. In Computer Science, polymorphism is a programming language feature that allows values of different data types to be handles using a common interface. There are three types : Ad-Hoc Polymosphism, Parametric Polymorphism, Subtype/Inclusion Polymorphism. Source: Wikipedia.


What kind of drugs commonly has polymorphism?

Polymorphism is common with barbiturates, steroids, and sulphonamides.


Is polymorphism exist between prokaryotes?

Yes, polymorphism exists between the prokaryotes.


What mode does an adhoc network use?

infrastructureless network..


What is Difference between dynamic polymorphism and static polymorphism with example?

Static polymorphism is used the concept of early binding or we can say compile time binding where as dynamic polymorphism used the concept of late binding or run time binding.


How can one detect polymorphism by genetic marker?

One can detect polymorphism by genetic marker using single-nucleotide polymorphism which is able to even tell mutation of a gene.


Is adhoc network the largest network?

adhoc basically means "thrown together". In the terms of a network it means the computers may not be related together by network name or domain name.


What is adhoc system development method?

this is the development of a system as at when it is required.