Book a Demo

Author Topic: c# - partial class - 2 boxes shown - need only one  (Read 12238 times)

OliverKosmann

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
c# - partial class - 2 boxes shown - need only one
« on: February 22, 2008, 05:07:58 am »
We have many partial classes in our class hierarchy.

How do I avoid the split into two boxes when creating the class diagram?
Can both classes be merged?
Can both boxes be glued together? (automatically?)

Thank you in advance.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: c# - partial class - 2 boxes shown - need only
« Reply #1 on: February 22, 2008, 05:16:34 am »
Hi Oliver,

I have found no reliable (or even practical) way to do this yet with EA. I suggest you watch EA 7.1, currently in beta 1, to see if this comes up.

[That does not mean that this is not possible, just that I've not noticed it. Check this thread to see if anyone can shine some more positive light on this subject.]

My guess is that this might involve tagged values of some sort. Perhaps you could kludge together a solution that way.

David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: c# - partial class - 2 boxes shown - need only
« Reply #2 on: February 22, 2008, 08:00:51 am »
EA currently supports partial classes by keeping them separate for two reasons.
  • So that code engineering can be performed on any of the parts.
  • To allow members to be added to the required class part/file.
We realise that this doesn't allow for a unified representation of the class as a whole, and that many users will have this requirement.  However, we believe that it is the best solution available at the moment.

At this stage we are unable to give a timeframe for when we would allow a unified representation of partial classes.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: c# - partial class - 2 boxes shown - need only
« Reply #3 on: February 22, 2008, 10:14:20 am »
Quote
We have many partial classes in our class hierarchy.

How do I avoid the split into two boxes when creating the class diagram?
Can both classes be merged?
Can both boxes be glued together? (automatically?)

Thank you in advance.
Hi again Oliver,

Actually, the Sparx solution makes a lot of sense. If you think about it, you will (generally) have two (or more as the case may be) 'parts' of partial class. I mean this in the sense that the actual code will occur in two (or more) files; each file corresponds to one partial class entity.

As far as your class hierarchy goes, I don't think you have a problem. The hierarchy itself only has a single instance of the class. The partial entities merely represent the way you have implemented implementation this single class in your code.

So, at the level of abstraction of your class hierarchy there is only a single entity. This is a high-level design. At the (lower) level of abstraction of your implementation design you have one lower-level element for each code file you will produce.

Of course there is a relationship between the two levels of design as well, which you might want to explicitly model. This could be done via a trace relationships, composite structure diagrams, or (perhaps) collaborations; perhaps some combination of these and others. That would depend on what you need to show, your audience, and your corporate standards.

Hopefully I've not muddied the waters too much...

David

PS: And don't go trashing your current model if you want to do things as above. Just create the x-thousand-foot view model and trace back to it from the design you have now. If the current model is producing usable results then it's not broken.
No, you can't have it!

OliverKosmann

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: c# - partial class - 2 boxes shown - need only
« Reply #4 on: February 22, 2008, 07:50:02 pm »
Quote
We realise that this doesn't allow for a unified representation of the class as a whole

I do not dislike the splitted representation, but I would prefer if there were an option for the
auto layouter, so that all  parts of  partial classes are positioned  adjoined to each other.

OliverKosmann

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: c# - partial class - 2 boxes shown - need only
« Reply #5 on: February 22, 2008, 07:55:35 pm »
Quote
So, at the level of abstraction of your class hierarchy there is only a single entity.

... and that is exactly what I want to see in a class diagram.
When looking on a class diagram, I am not interested in the file structure but in class hierarchy.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: c# - partial class - 2 boxes shown - need only
« Reply #6 on: February 23, 2008, 12:26:55 am »
Quote
Quote
So, at the level of abstraction of your class hierarchy there is only a single entity.

... and that is exactly what I want to see in a class diagram.
When looking on a class diagram, I am not interested in the file structure but in class hierarchy.
So draw exactly that...

Try drawing the class diagram without the partials at all. Then for each class that will have partials, right-click and make it a composite element. This will give you a composite structure diagram within the class. On the inner diagram create the partial class elements.

You might have to fiddle a bit with your generate options. That's not a real problem, but a symptom of modeling at two different levels of abstraction. Consider the single-element-per-class level as an upper level and imagine doing all the 'development' level design at a lower level (for all classes) and it makes sense.

BTW, if you prefer you can change the composite structure diagram into a class diagram from the main menu. Open the diagram and choose Diagram | Change Type.

David

PS: Another way to go about all of this would be to put the two classes close together and put a boundary around them. You could even make the boundary borders invisible. Unfortunately EA does a poor job of handling boundaries on layout.
No, you can't have it!

OliverKosmann

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: c# - partial class - 2 boxes shown - need only
« Reply #7 on: February 25, 2008, 11:09:18 pm »
Quote
So draw exactly that...
Good idea, but ...
I don't dray anything, I am analyzing existing code.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: c# - partial class - 2 boxes shown - need only
« Reply #8 on: February 26, 2008, 12:39:01 am »
OK,

I think I see what you mean. You are getting the models 'ready made' from the legacy (or preexisting) code.

Here's an idea that might work. [Please note the word "might" in that sentence. I just came up with this when I read your last post a few seconds ago. I have not thought it through.]

When you see a set of generic class elements - by "set" I mean those that represent the same actual class - create a 'master' element for the class, without any contents. Make that class a composite element. By doing so you will create a diagram 'underneath' the new class element. By default this 'inner' diagram won't be a class diagram. [I think it will be a composite structure diagram, but I don't have EA open to check that right now; it's not important though, as you'll see in a moment.]

Make sure the 'inner' diagram is active - it should be activated when you make its parent a composite element - and from the main menu choose Diagram | Change Type. [Note that you [/i]must[/i] do this from the main menu; there is no equivalent context menu choice.] Change the diagram to a class diagram.

Now go back to the 'parent' diagram. For each of the partial class elements of the current set, move any relationships to the new generic class element. [There is a shortcut to do this easily. Use shift-click (or is it control-click) to select the connector end you want to move, then drag it to the new target and let it go.]

Finally select all the generic class elements, and drag them to the new 'inner' diagram. You might want to select them in the Project Browser and drag them into the composite class as well; that's up to you.

David

[PS: If you try this please do it on a copy of your model. I don't know if this will affect code generation or other such things.

And oh yes, if you try it please let us know what happens, for better or for worse.]
No, you can't have it!

Bart Reyserhove

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: c# - partial class - 2 boxes shown - need only
« Reply #9 on: March 05, 2008, 11:23:59 pm »
If you are reverse engineering the classes from an existing code base, there is a possibility to have only one class.

The solution is to reverse engineer based on the assemblies (Import binary module). The notion of partial classes does not exist anymore in the assembly, they are merged at compile time.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: c# - partial class - 2 boxes shown - need only
« Reply #10 on: March 06, 2008, 02:26:51 am »
That is quite true. There really is only a single class. But if you are talking about low-level design - what goes where - you will want to identify the partial classes. After all, they may be in separate files, and some may be machine-generated (from the start) while others are created by your developers.

That's the whole point of having high and low level viewpoints of your design models at different levels of abstraction. [EDIT: Perhaps this wording will be clearer.]
« Last Edit: March 06, 2008, 02:55:48 am by Midnight »
No, you can't have it!