home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.object
- Path: sparky!uunet!rational.com!melody!paul
- From: paul@melody.Rational.com (Paul Jasper)
- Subject: Re: Booch question: new class relationship?
- Message-ID: <1993Jan28.204928.10352@rational.com>
- Sender: paul@melody (Paul Jasper)
- Reply-To: paul@rational.com
- Organization: Rational
- References: <894@ulogic.UUCP> <rmartin.727740331@thor>
- Date: Thu, 28 Jan 1993 20:49:28 GMT
- Lines: 58
-
- In article <rmartin.727740331@thor>, rmartin@Rational.COM (Bob Martin) writes:
- > hartman@ulogic.UUCP (Richard M. Hartman) writes:
- >
- > You can mail a letter to prod_info@rational.com asking them for
- > Booch's latest paper on the notation. In that paper you will find
- > what you are looking for.
-
- This is now available by e-mail in PostScript form, from the same address
- (or phone 1-800-ROSE-237).
-
- > Containment by value represents the notion that the storage of the
- > contained class exists within the storage of the containing class.
- > The containing class has intrinsic knowledge of the contained class
- > (ie. knows where to find it). The contained class is created and
- > destroyed with the containing class.
-
- Yes, this is correct, but then you add:
-
- > The contained class cannot be polymorphic.
-
- Tut, tut, Bob! You should know this ;^)
-
- "Has by value" doesn't necessarily imply physical containment. The
- "intrinsic knowledge" may still be a pointer or even a database reference,
- but the semantics will still be that instances of the sub-class are
- created and destroyed with the parent object.
-
- Hence, polymorphism is perfectly acceptable. In fact, it is used quite
- frequently. For example, in designing a tree, you might have an abstract
- base class representing a node. The child nodes can be represented by a
- circular "has by value" relationship back to itself (er, "reflexive"?).
- Obviously, this can't be implemented by physical containment. Concrete
- sub-classes inheriting from the node class can then be defined for each
- of the types of data to be stored in the tree, for example, to allow
- mixed trees of strings, integers and reals with polymorphic behavior.
-
- >
- > class ContainingByValue
- > {
- > Contained x;
- // or Contained *x;
- > };
-
- class ContainingByValue
- {
- ContainingByValue **children;
- };
-
- class ContainingByValueString: ContainingByValue
- {
- char *data;
- };
-
- --
- -- Paul Jasper
- -- RATIONAL
- -- Object-Oriented Products
- --
-