magazine resources subscribe about advertising

New Architect Daily
Commentary and updates on current events and technologies

CMP Media E-Book

Download your copy today.

Research
Search for reports and white papers from industry vendors and analysts.

This Week at NewArchitect.com Subscribe now to our free email newsletter and get notified when the site is updated with new articles







Day of Defeat Online Gaming

 New Architect > Archives > 1997 > 02 > Java Alley  

Discovering Information at Run Time

Over the next couple of months, I'll look at the two ways that Java allows you to discover information about objects and classes at run time: traditional run-time type information (RTTI) mechanism, which assumes you have all the types available at compile time and run time; and the "reflection" mechanism in Java 1.1, which allows you to discover class information solely at run time.

Run-time type identification seems fairly simple at first. It lets you find the exact type of an object when you have only a handle to the base type. However, the need for RTTI uncovers a plethora of interesting object-oriented design issues, and raises fundamental questions about program structure.

The Need for RTTI

Consider a class hierarchy that uses polymorphism. The generic type is the base class shape, and the specific derived types are circle, square, and triangle; see Figure 1.

Normally in object-oriented programming, the bulk of your code manipulates handles to the base type (shape, in this case), so if you extend the program by adding a new class (rhomboid, derived from shape, for example), most of the code is not affected. In this example, the dynamically bound function in the shape interface is draw(), so the client programmer would call draw() through a generic shape handle.




  Day of Defeat Online Gaming

home | daily | current issue | archives | features | critical decisions | case studies | expert opinion | reviews | access | industry events | newsletter | research | careers | info centers | advertising | subscribe | subscriber service | editorial calendar | press | contacts


Copyright © 2006 CMP Media, LLC Read our privacy policy, your California privacy rights, terms of service.
SDMG Web sites: BYTE.com, C/C++ Users Journal, Developer Pipeline, Dr. Dobb's Journal, DotNetJunkies, MSDN Magazine, Sys Admin,
SD Expo, SD Magazine, SqlJunkies, The Perl Journal, Unixreview, Windows Developer Network, New Architect

web2