Circular dependencies

Discussion in 'C++' started by ernesto basc?n pantoja, Nov 29, 2004.

  1. 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
     
    ernesto basc?n pantoja, Nov 29, 2004
    #1
    1. Advertising

  2. On 29 Nov 2004 07:40:16 -0800, (ernesto basc?n
    pantoja) wrote:

    >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.

    --
    Bob Hairgrove
     
    Bob Hairgrove, Nov 29, 2004
    #2
    1. Advertising

  3. "ernesto basc?n pantoja" <> wrote in message news:...
    > 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.

    --
    --Larry Brasfield
    email:
    Above views may belong only to me.
     
    Larry Brasfield, Nov 29, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Suzanne Vogel
    Replies:
    2
    Views:
    2,619
    Suzanne Vogel
    Jun 26, 2003
  2. crichmon
    Replies:
    3
    Views:
    764
    crichmon
    Jun 28, 2004
  3. Dylan
    Replies:
    7
    Views:
    566
    Dylan
    Jul 7, 2004
  4. Kiuhnm
    Replies:
    16
    Views:
    745
    Jonathan Mcdougall
    Jan 3, 2005
  5. ro86
    Replies:
    4
    Views:
    563
Loading...

Share This Page