From: jrobie@netmbx.netmbx.de (Jonathan Robie)
Subject: Re: Covariant Types in Derived Classes
Organization: netmbx, Berlin, Germany
Date: Fri, 24 Jul 1992 14:17:57 GMT

maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:

>>If I want a generic print function that can handle all types as though they
>>were basic types, then this print function must know the location and type
>>of each member, and also the name if the function is to be particularly
>>useful.

>	Such a utility function would be useful for debugging only.
>Yes, to do it you would need RTTI.

Not so.  A report generator might start by showing me the default
printout for an object.  I can grab fields with my mouse and move
them around or delete them.

A user interface tool might allow me to do something similar by providing
me with a default, editable window.

Debugging is another obvious application, as you mention.

So far we have seen that RTTI is very useful for debuggers, class browsers,
report generators, user interface tools, databases, communications...
in other words, for a great deal of the programming tools a C++ programmer
would like to have.

>	To make proper output *requires* programmer definition,
>when I need this I just have a virtual print in all relevant classes.
>Of course, then I have to *write* the definitions, which is a pain.

But providing a default which may be used directly or edited with
a mouse is not a pain, and is easily provided as a general tool.

>	Oh, you mean that the database does NOT actually define new 
>objects, the user has to write a program to create them?
>(To supply the constructor, which must be compiled C++ code)
>Then the OODB just stores the stuff, and has to retrieve
>it and convert it back to an object, which is a bit
>of a problem even WITH RTTI (because the object doesn't yet
>exist, so the RTTI is useless).

Let me give you an example from POET, the OODB that I know
best (because I am one of the developers).  Let's say you have
an arbitrary class declaration:

	class ArbitraryClass {
		int foo;
	public:
		float goo;
	};

If you just write the little word "persistent" in front of this then
our precompiler will know that it should generate run time type info:


	persistent class ArbitraryClass {
		int foo;
	public:
		float goo;
	};

If an object is assigned to a database then you can store it using
the Store() method, which is provided for all persistent objects:

	ArbitraryClass ArbitraryObject;

	ArbitraryObject->Assign(ADatabase);
	ArbitraryObject->Store();

I'll avoid going into more detail right now, but you see that this
is very convenient.  Without RTTI it is not possible.  We do not need
a reflective system, but we do need an introspective system.  Since
C++ is not introspective, we have built our own compiler to give us the
information which all C++ compilers generate and then throw away.

>	Yes. 'tis why I am concerned that RTTI will be used
>to do downcasting, which, although not invalidating type safety,
>invalidates the open/closed principle.

I am concerned that many C++ programs downcast without any guarantee
of type safety.  Start reading large C++ programs and you will see that
downcasts are quite common.  Is the C++ community worse off if we provide
a safer way to do this?

>	The problems you want to solve (me too, and many others :-)
>are way out of te scope of a traditional language which
>works only with memory resources. THAT is the problem, really.

Naw.  The problems *I* am discussing have  already been solved
using C++, but we are finding sneaky ways to get at run time type
information.

>	Wouldn't you rather just say 'persistent' and have the object
>just exist in the 'persistent'  database totally automatically :-)

	Because the user shyould have some control over which objects
	get stored, and should be able to test the store operation for
	error returns.  But you have the right idea!  And if you look
	at my sample code given above--from a commercial system that
	is now available--you see that this kind of high level access
	is possible in C++ today, given RTTI.
-- 
Jonathan

===========================================================================

Newsgroups: comp.lang.c++