CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020

    Multiple Inheritence in generated code

    I have the following problem when I use Rational Rose.

    The Original Problem: I draw the diagram and get Rose to generate the code. I then modify the generated code to add the implementation. This is quite hairy as Rose puts in tons of comment to help its preprocessor draw the diagrams and it is difficult to see the wood for the trees. Further down the line, I have to make modifications to the diagram. If I generate the new code, it wipes out my original implementation.

    My Half Solution: Instead of modifying the generated code, I derive from it in an implementation class. I don't need to modify the generated code and all looks well. I can keep on modifying the diagrams and just add to the implementation classes. In a character drawing of UML, it looks like
    Code:
        GenBase <----- ImplBase
           ^
           |
        GenDerived1<-- ImplDerived1
           ^
           |
        GenDerived2<-- ImplDerived2
    The problem is that, if I wish to call a method from a base class, I can only call the ones in GenXXX: not ImplXXX but really, what I would like to call the ones in ImplXXX, so I now end up with
    Code:
        GenBase <----- ImplBase
           ^               ^
           |               |
        GenDerived1<-- ImplDerived1
           ^               ^
           |               |
        GenDerived2<-- ImplDerived2
    This is a multiple inheritence tree where almost every call needs a class qualifier in front of it. I thought of using smart pointer where the implementation somehow pulls in the derived class but I'd have to use some sort of macro to map between the generated class and the implementation class. Obviously, my half solution is wrong. Is there a better way of doing this?
    Succinct is verbose for terse

  2. #2
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    First off, I sympathise with you having to use Rose. I used it for a while and thought it was one of the worst-designed programs I'd come across (not counting Outlook, of course, which takes all the awards in that arena).

    I thought it kept any implementation code (as long as you don't completely change the interface) - that's what all those irritating model IDs are for. However, I'm pretty sure you can store your implementation code in your Rose model, so that it will generate it with the rest. It's a bit tricky, but can be done - actual details depend on which of the three C++ generators you're using.

    As to your solution - I think your problem may stem from "misusing" the pimpl idiom. In this case, the "Gen" hierarchy is the important one - you have to program against its interface, and rely on the Gen classes passing it on to the impl classes, so ImplDerived2 ought to use ImplDerived1 indirectly through the Gen classes, not directly through inheritance. What you're describing tends to suggest that your Impl classes are not true implementations, since there are bits that you can't get at through the Gen classes (unless I've misunderstood).

    Without knowing what your problems actually are, have you considered using the Template method? I've found this to be quite useful in some hierarchies. You do common work in the base class, and anything that's variable over specialisation is consigned to a private virtual function:
    Code:
    class Base
    {
    public:
        void DoSomething()
        {
            // Do some common work (using own pimpl class?)
            VariableBit1();
            // Some more common work
            VariableBit2();
        }
    private:
        virtual void VariableBit1() /* = 0 */;
        virtual void VariableBit2() /* = 0 */;
    };
    Basically, can you rejig GenDerived1 so that it passes bits down to GenDerived2 (and thus, ImplDerived2), rather than have Gen/ImplDerived2 go back up to Gen/ImplDerived1? It means you have to figure out how to keep the Gen code in the Rose model, but I'm sure that can be done.

    Like I say, I have no idea whether this will work for your particular problem, but I've found it quite useful in the past.

    Caveat: all the above is pure speculation on my part.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  3. #3
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    I agree with you: Rose and Outlook are the two worst programs I've ever used. Outlook is worse than Rose, especially over a modem. In the past, I've only used Rose for diagrams: I've never used it to generate code.
    I thought it kept any implementation code (as long as you don't completely change the interface) - that's what all those irritating model IDs are for. However, I'm pretty sure you can store your implementation code in your Rose model, so that it will generate it with the rest. It's a bit tricky, but can be done - actual details depend on which of the three C++ generators you're using.
    I'll have to investigate this. I'm not a fan of drawing tools so I just took the experienced user's word for it that this wasn't possible. If I can't figure it out then I'll just use patch to restore the code.
    Basically, can you rejig GenDerived1 so that it passes bits down to GenDerived2 (and thus, ImplDerived2), rather than have Gen/ImplDerived2 go back up to Gen/ImplDerived1?
    I can rejig the classes: that is not a problem. The Gen/Impl thing was my idea. It is just a concept at the moment. We are still in the design phase and everyone is busy with Rose so it can go in any direction before the coding starts. It is a new toy for most people and we haven't thought that far ahead yet. I just have to figure out a strategy that will work.

    I'll also try the template method and see where that takes me. It may be the answer to my Rose Woes and the start of template problems but it is easier to handle template problems. It won't be long before someone asks How do you draw templates in Rose?
    Succinct is verbose for terse

  4. #4
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    Template method != template class. Template method refers to the Base class function acting as a sort of "boilerplate" code, which the actual derived class fills in the blanks for.

    You can do template classes in Rose - they appear as a normal class but with a dashed box containing the template parameters in the top left corner. They're not called "template", though - something like "parameterized class" or some such. It's in the help.

    I wrote a few Rose macros to generate things like pimpls and Singletons automatically - I was certainly able to embed a small amount of code into the member functions as part of that. If you think the UI is bad, wait till you try writing macros.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  5. #5
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    On another note, is there any program like Rose but which you think is better ?

  6. #6
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    There are other programs around, but I've not tried any of them.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  7. #7
    Join Date
    May 2002
    Location
    Quebec City, Canada
    Posts
    374
    Together from www.togethersoft.com is great, albeit a little slow for big projects.
    Martin Breton
    3D vision software developer and system integrator.

  8. #8
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    There is one that is very similar to Rose: Microsoft Visual Modeller. It comes with VC++. I've used it a few times just to generate the pretty pictures.
    Succinct is verbose for terse

  9. #9
    Join Date
    May 2002
    Location
    Quebec City, Canada
    Posts
    374
    Is it with .NET?
    Martin Breton
    3D vision software developer and system integrator.

  10. #10
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020

    Microsoft Visual Modeller

    I've got no idea whether it is with .net. It comes with VC6.
    Succinct is verbose for terse

  11. #11
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    But cup: MS Visual Modeller is Rose, but without the good bits!
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  12. #12
    Join Date
    May 2002
    Location
    Quebec City, Canada
    Posts
    374
    That's weird because I have VC6 and I don't have modeler ;(
    Martin Breton
    3D vision software developer and system integrator.

  13. #13
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    Yup - I know Visual Modeller is a bodged version of Rose. Everything seems very 3-tierish too.

    Sorry - I meant Visual Studio: not Visual C++. I'm using the Enterprise edition which has everything, including lots that I do not use (eg Visual Foxpro).
    Last edited by cup; September 25th, 2002 at 03:17 PM.
    Succinct is verbose for terse

  14. #14
    Join Date
    May 2002
    Location
    Quebec City, Canada
    Posts
    374
    Ah Ok!
    Martin Breton
    3D vision software developer and system integrator.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured