Re: Clean Object Class Design -- What is it?

From: Carl Rosenberger <carl_at_db4o.com>
Date: Thu, 26 Jul 2001 20:44:43 +0200
Message-ID: <9jpoi8$qj9$07$1_at_news.t-online.com>


Mikito Harakiri wrote:
> >Does anyone have any pointers to a programming language that supports
> >navigating from child to parent? Reference count garbage collectors could
> >easily support this feature, but as I understand they are not
> >state-of-the-art.
> >
> In java it is common for a child to have many parents.

Sure.

> Which parent would you
> like to navigate to? To return a collection of pointers? Which collection:
> array, vector, enumeration?

My first-thought-approach:
An array of Object would be fine, since you would not manipulate it. A getParents() method would do. It would reduce a lot of maintenanace work that is commonly necessary to create trees with bidirectional navigation capabilities.

On a second look:
Every other accidental reference to an object would bloat the "getParents()" result. You could handle this by checking the class of the parent and possibly the variable name. O.K. forget it, this does not look elegant anymore.

It would only remain nice, if there would be a typesafe non-string way of specifying the field of a class. (One of my RFEs, but seemingly of no interest).

An example:

class Foo{
  Object bar;
}

Java allows me to use:
Foo.class

To specify a Field object quickly, without using Foo.class.getDeclaredField("bar"), I would wish to have the notation: Foo.bar.field

The point is that I hate to use reflection, if I have to introduce *strings* into my code, without having a chance that changes will be detected by the compiler. Obfuscators also get problems with strings.

(A side note: Foo.bar.field would be great for S.O.D.A.)

Back to the original feature:
Foo[] foos = (Foo[])myObject.getParents(foo.bar) would be convenient.

What do you think, Mikito?

Kind regards,
Carl

---
Carl Rosenberger
db4o - database for objects - http://www.db4o.com
Received on Thu Jul 26 2001 - 20:44:43 CEST

Original text of this message