Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

containment, one-to-many relaionship or Inheritance?

0 views
Skip to first unread message

Camilo

unread,
Nov 12, 1999, 3:00:00 AM11/12/99
to
Please, don't behead me with the "off-topic ax". My question was a C++ one,
which is the langauge I am using for this project.

I was having a hard time thinking out a model for these kinds of
"containment" situations, which I don't believe to be esoteric ones.

Do you know about C++ programming of containment types of models? I have
scanned all the C++ bibles around here and I haven't found pretty much
nothing about these programming situations.

Thank you
Camilo

Jeff Connelly <jeff_c...@mgv.com> wrote in message
news:80hfh5$tvv$1...@nnrp1.deja.com...
> You are correct, inheritance would be a bad idea in that case. That is
> composition, or "containment" as you said. Perhaps a TextBank would
> contain a vector of Texts, and a Text would contain a vector of
> strings. But I would like to point out that you should distinguish
> between "What are the benefits of using C++ to solve this?" and "What
> are the benefits of using OO to solve this?" Which is your question?
>
> In article <80h28n$7j6$1...@bgtnsc03.worldnet.att.net>,
> "Camilo" <Cml...@worldnet.att.net> wrote:
> > Hi,
> >
> > I need to model sort of a containment, one-to-many relaionship as
> > follows:
> > (contains)
> > I._ 1 Text Bank many Texts
> > II._ 1 Text many disjoint sequences of charaters
> > III._ 1 sequence a number of chained characters
> >
> > The thing is that this type of model is not a good candidate for an
> > inheritance hierarchie, among other things because there won't really
> be
> > derived classes, it is more sort of a one-to-many relationship.
> >
> > Other than making use of the OO encapsulation I don't see how can I
> > model/where are the benefits of coding it in C++.
> >
> > Thanks
> > Camilo
> >
> >
>
> --
> Regards,
> Jeff
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

[ Send an empty e-mail to c++-...@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]


Knut Stolze

unread,
Nov 13, 1999, 3:00:00 AM11/13/99
to
In comp.lang.c++.moderated, Camilo wrote:
> Please, don't behead me with the "off-topic ax". My question was a C++ =

one,
> which is the langauge I am using for this project.
>
> I was having a hard time thinking out a model for these kinds of
> "containment" situations, which I don't believe to be esoteric ones.
>
> Do you know about C++ programming of containment types of models? I =

have
> scanned all the C++ bibles around here and I haven't found pretty much
> nothing about these programming situations.
>
> Thank you
> Camilo
>
> Jeff Connelly <jeff_c...@mgv.com> wrote in message
> news:80hfh5$tvv$1...@nnrp1.deja.com...
> > You are correct, inheritance would be a bad idea in that case. That =

is
> > composition, or "containment" as you said. Perhaps a TextBank would
> > contain a vector of Texts, and a Text would contain a vector of
> > strings. But I would like to point out that you should distinguish
> > between "What are the benefits of using C++ to solve this?" and =
"What
> > are the benefits of using OO to solve this?" Which is your =

question?
> >
> > In article <80h28n$7j6$1...@bgtnsc03.worldnet.att.net>,
> > "Camilo" <Cml...@worldnet.att.net> wrote:
> > > Hi,
> > >
> > > I need to model sort of a containment, one-to-many relaionship =

as
> > > follows:
> > > (contains)
> > > I._ 1 Text Bank many Texts
> > > II._ 1 Text many disjoint sequences of =

charaters
> > > III._ 1 sequence a number of chained characters
> > >
> > > The thing is that this type of model is not a good candidate for =
an
> > > inheritance hierarchie, among other things because there won't =

really
> > be
> > > derived classes, it is more sort of a one-to-many relationship.
> > >
> > > Other than making use of the OO encapsulation I don't see how can =

I
> > > model/where are the benefits of coding it in C++.

Your example is a simple aggregation (part-of relationship). You should =
look
for that in your books. If you don't find it than an OO book or a OO =
design
pattern book would be helpful.

cu,
Knut
--
Don't trust everything you hear and don't trust anything you say.

Camilo

unread,
Nov 14, 1999, 3:00:00 AM11/14/99
to
Well, I have checked every book around here:

Bjarne Stroustrup's The C++ Prog ..., The Design and evolution ...
Scott Meyer's Effective C++
Jamsas's C/C++ Bible
...

and found very little about the topic.

Also, I did a search and only found scattered info, which I took the time to
read through.
For example I found at http://www.objectcentral.com/oobook/webch2.htm

... "Object-oriented programming languages have differing levels of support
for whole/part and generalization/specialization hierarchies. Most OO
programming languages, including C++, haven't defined special language
support for whole/parts. Nevertheless, whole/part hierarchies are critical
for most OO designs. The common OO term for a whole/part hierarchy is
aggregation."

I also found at: http://www.rug.nl/rugcis/rc/ftp/unix/FAQ/C++-FAQ/part11

Q73: Do most C++ programmers use containment or private inheritance?
A: Short answer: generalizations are always wrong (that's a generalization
:-).

The long answer is another generalization: most C++ programmers use regular
containment (also called `composition' or `aggregation') more often than
private inheritance. The usual reason is that they don't *want* to have
access
to the internals of too many other classes.

Private inheritance is not evil; it's just more expensive to maintain, since
it
increases the number of classes that have access to `internal' parts of
other
classes (coupling). The `protected' parts of a class are more likely to
change
than the `public' parts.

-----------------------------------------------------------------
?

This type of model is really importan to me do you know about books that go
into detail with this issue?

Thanks
Camilo


Knut Stolze <sto...@us.ibm.com> wrote in message
news:1999111303...@kstolz.stl.ibm.com...

[ Send an empty e-mail to c++-...@netlab.cs.rpi.edu for info ]

0 new messages