FACTOID # 144: A three-minute local phone call in Ecuador costs 60 U.S. cents, 60 times as much as in Ukraine, Macedonia, Saudi Arabia, Nepal, or Uzbekistan.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Type introspection

In computing, type introspection is a capability of some object-oriented programming languages to determine the type of an object at runtime. This is a notable capability of the Objective C language.


In Objective C, for example, both the generic Object and NSObject (in Cocoa/OpenStep) provide the method isMemberOfClass: which returns true if the argument to the method is an instance of the specified class. The method isKindOfClass: analogously returns true if the argument inherits from the specified class.


For example, say we have a Puppy and Kitten class inheriting from Animal, and a Vet class.


Now, in the desex method we can write

 - desex: (id) to_desex { if([to_desex isKindOfClass:[Animal class]]) { //we're actually desexing an Animal, so continue if([to_desex isMemberOfClass:[Puppy class]]) desex_dog(to_desex); else if([to_desex isMemberOfClass:[Kitten class]]) desex_cat(to_desex); else error(); } else { error(); } } 

Now, when desex is called with a generic object (an id), the function will behave correctly depending on the type of the generic object.


Type introspection can be used to implement polymorphism.


  Results from FactBites:
 
Type polymorphism: Information from Answers.com (3003 words)
In these languages, subtyping polymorphism (sometimes referred to as dynamic polymorphism or dynamic typing) allows a function to be written to take an object of a certain type T, but also work correctly if passed an object that belongs to a type S that is a subtype of T (according to the Liskov substitution principle).
This type of polymorphism is common in object-oriented programming languages, many of which allow operators to be overloaded in a manner similar to functions (see operator overloading).
For instance, it is usually possible to convert a value of a floating-point numeric type into a value of integer type with a rounding operation, or to convert an integer to a string using a function that constructs the integer's decimal representation.
PEP 252 -- Making Types Look More Like Classes (3810 words)
For example, you can't directly subclass the dictionary type, and the introspection interface for finding out what methods and instance variables an object has is different for types and for classes.
The class-based introspection API is used primarily for class instances; it is also used by Jim Fulton's ExtensionClasses.
The type API is sometimes combined with a __dict__ that works the same as for instances (for example for function objects in Python 2.1, f.__dict__ contains f's dynamic attributes, while f.__members__ lists the names of f's statically defined attributes).
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.