Circular dependencies

  • Thread starter ernesto basc?n pantoja
  • Start date
E

ernesto basc?n pantoja

Hi everybody:

I'm implementing a general C++ framework and I have a basic question
about circular dependencies:

I am creating a base class Object, my Object class has a method
defined as:
virtual String toString();

where String is defined as:

class String : public Object

This is similar to the Java or .NET Object class implementation, but
it
is not a good OO design because the circular dependency between my
Object and my String classes.

There are another ways to implement this functionality without having
circular
dependencies?

Best regards



ernesto
 
B

Bob Hairgrove

Hi everybody:

I'm implementing a general C++ framework and I have a basic question
about circular dependencies:

I am creating a base class Object, my Object class has a method
defined as:
virtual String toString();

where String is defined as:

class String : public Object

This is similar to the Java or .NET Object class implementation, but
it
is not a good OO design because the circular dependency between my
Object and my String classes.

There are another ways to implement this functionality without having
circular
dependencies?

Yes ... use std::string, or don't make your String an Object, but a
stand-alone class.
 
L

Larry Brasfield

ernesto basc?n pantoja said:
Hi everybody: Hi.

I'm implementing a general C++ framework and I have a basic question
about circular dependencies:

I am creating a base class Object, my Object class has a method
defined as:
virtual String toString();

where String is defined as:

class String : public Object

This is similar to the Java or .NET Object class implementation, but it
is not a good OO design because the circular dependency between my
Object and my String classes.

I have never heard of this precept before, and I doubt that it is
a generally held view. In fact, I think it is rare for frameworks
to be designed without any circular dependency whatsoever.
There are another ways to implement this functionality without having
circular dependencies?

You have set out "this functionality" as:
(1) an object hierarchy with a single root
(2) any object can be converted to a "String"
(3) a "String" is part of the object hierarchy
That inherently has some circularity, hence circular dependency.
So I have to say, "No there are no other ways to implement that
functionality without some degree of circular dependency." The
issue is not implementation; it is your requirements.

I suggest simply dropping the "not a good OO design" notion.
If you have a specific C++ question about how to declare and
define classes with circular dependency(s), you are welcome
to pose them. C++ provides ways to accomplishing that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top