Click to See Complete Forum and Search --> : Multiple Inheritence in generated code
cup
September 24th, 2002, 06:54 AM
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
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
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?
Graham
September 24th, 2002, 07:45 AM
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:
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.
cup
September 24th, 2002, 09:04 AM
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?
Graham
September 24th, 2002, 09:53 AM
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. :mad:
Yves M
September 24th, 2002, 10:14 AM
On another note, is there any program like Rose but which you think is better ?
Graham
September 24th, 2002, 10:38 AM
There are other programs around, but I've not tried any of them.
proxima centaur
September 24th, 2002, 10:52 AM
Together from www.togethersoft.com (http://www.togethersoft.com) is great, albeit a little slow for big projects.
cup
September 24th, 2002, 11:23 AM
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.
proxima centaur
September 24th, 2002, 03:12 PM
Is it with .NET?
cup
September 24th, 2002, 11:48 PM
I've got no idea whether it is with .net. It comes with VC6.
Graham
September 25th, 2002, 03:44 AM
But cup: MS Visual Modeller is Rose, but without the good bits!
proxima centaur
September 25th, 2002, 01:08 PM
That's weird because I have VC6 and I don't have modeler ;(
cup
September 25th, 2002, 01:28 PM
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).
proxima centaur
September 26th, 2002, 09:57 AM
Ah Ok! :)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.