Book a Demo

Author Topic: Collection Class on Class Diagram  (Read 8951 times)

Tryst

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Collection Class on Class Diagram
« on: December 13, 2007, 03:12:53 pm »
Hi all,

here is a simple question for you. If I have a class diagram which has a classes and a class which is to be a collection of these classes, how do I model a collection class on a class diagram?

Thanks in advance
Tryst

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Collection Class on Class Diagram
« Reply #1 on: December 13, 2007, 04:45:10 pm »
You might create the collection container as a class. Then you could have an attribute that has a multiplicity of zero-to-many. Set this on the Detail tab of the Attributes dialog. Note that you must save the attribute (at least the name) before the fields on the Detail tab become enabled.

If you need to reference a collection in an attribute of some other class, then you can set the attribute's type to the class above.

You can also use the Detail tab of an attribute to indicate that the attribute is a collection.

Play around a bit, you'll get the hang of it.

HTH, David
No, you can't have it!

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Collection Class on Class Diagram
« Reply #2 on: December 13, 2007, 05:16:27 pm »
How about...

The Sparx Team
[email protected]

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Collection Class on Class Diagram
« Reply #3 on: December 13, 2007, 10:32:28 pm »
No, no, no.  >:(

There is only one instance of the collection class in the parent object.

: person
private MyWallet wallet

: wallet
private MyCash[0..*] cash

(though in my case, it usually tends to the lower end of the cardinality :-/ )

The collection contains a bunch of stuff. The "bunch" is an attribute of the collection class, represented as a fixed (statically defined) or variable number of known (typed) or unknown ("object")  objects.

bruce
« Last Edit: December 13, 2007, 10:33:15 pm by sargasso »
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

jeshaw2

  • EA User
  • **
  • Posts: 701
  • Karma: +0/-0
  • I'm a Singleton, what pattern are you?
    • View Profile
Re: Collection Class on Class Diagram
« Reply #4 on: December 14, 2007, 09:04:21 am »
Bruce;
I don't think I understand your post.
Are you saying "no" to KP's diagram?
-Jim
Verbal Use Cases aren't worth the paper they are written upon.

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Collection Class on Class Diagram
« Reply #5 on: December 14, 2007, 12:03:45 pm »
Yes.

A collection class is the "bag". It holds the things that are collected and the methods use to manipulate those things.  Consider a .NET dictionary type of collection.  The "things" are a set of (for wnat of a better example) term/definition pairs and a set of methods to inspect and manipulate these pairs.

So, the cardinality is the other way around

[cCollection] -0..*-------------> [cItem]

and when the collection class is used

[cCollector] -1-------->[cCollection] -0..*-------> [cItem]

bruce
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

Tryst

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Collection Class on Class Diagram
« Reply #6 on: January 06, 2008, 11:40:17 am »
Hi all, and thanks for the replies.

Below is an image I have taken of a small part of my diagram where I have tried to implement a collection Class. I have done it through the two methods mentioned in this thread. I have gone in and edited the 'Details' property of the attribute (attribute name is _courtFindings) and set it as a Collection. I have also created a Separate Class (CompanyCourtFilings) and done the associations as seen on the diagram. Is there no one specific way?

(sorry, its not exactly intuitive to add images on this forum :-s)

Also, ultimately in the C# code I will represent the collection as a Generic ArrayList (ArrayList<CompanyCourtFilings>), but I am guessing that Generics has no meaning in EA at the moment?

Thanks
Tryst

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Collection Class on Class Diagram
« Reply #7 on: February 23, 2008, 04:57:28 pm »
Hi,

I've been doing some research on this subject lately in function of an MDA project I'm working on.
I think the disagreement could be related to the different views a modeller could have. MDA defines the concepts of a PIM (Platform Independant Model) and a PSM (Platform Specific Model). In a PIM I would model the fact that my ClassA has a relation with several ClassB's as a simple association.  In a PSM I would want to model it as ClassA having an attribute of type ClassB with the multiplicity set to [0...*]. To define which type of collection you actually want to model UML has two important attributes: isUnique and IsOrdered. In EA they relate tot he properties "Ordered" and "Allow Duplicates" on the details of both an attribute (PSM way) and the end of an assocation (PIM way)
The combination of these two binary properties define the collection type.
isOrderedisUniqueCollection type
FalseTrueSet
TrueTrueOrderedSet
FalseFalseBag
TrueFalseSequence

The default collection type most people would want to use is the Set. That is probably why in EA the isUnique property is reversed. (you need to check "allow duplicated" in make isUnique false).
Most modern programming languages have a premade collection for each of these collection types. If you are lucky they even have the same name. So in theory EA should be able to generate the correct collection type out of you PIM or you PSM type of model.
I must admit, I've never used the code generation feature in EA so someone else will have to verify that.

I would have posted some pictures here to illustrate, if i was straightforward to add an image to the post.

jeshaw2

  • EA User
  • **
  • Posts: 701
  • Karma: +0/-0
  • I'm a Singleton, what pattern are you?
    • View Profile
Re: Collection Class on Class Diagram
« Reply #8 on: February 24, 2008, 03:14:36 pm »
Quote
Yes.

A collection class is the "bag". It holds the things that are collected and the methods use to manipulate those things.  Consider a .NET dictionary type of collection.  The "things" are a set of (for wnat of a better example) term/definition pairs and a set of methods to inspect and manipulate these pairs.

So, the cardinality is the other way around

[cCollection] -0..*-------------> [cItem]

and when the collection class is used

[cCollector] -1-------->[cCollection] -0..*-------> [cItem]

bruce
So if I understand you correctly, you make a distinction between
  • The Items collected {cItem}
  • the set of items collected (taken as a holonym) {cCollection}; and,
  • The container (in which the set logically resides) that provides the set manipulation behaviors. {cCollector}
Verbal Use Cases aren't worth the paper they are written upon.

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Collection Class on Class Diagram
« Reply #9 on: February 25, 2008, 09:33:55 pm »
Quote
So if I understand you correctly, you make a distinction between

    * The Items collected {cItem}
    * the set of items collected (taken as a holonym) {cCollection}; and,
    * The container (in which the set logically resides) that provides the set manipulation behaviors. {cCollector}

Exactly!.  
MODEL 1
Class "house" has the following attributes
MyBedrooms[5]:room
MyKitchen:room
...

both of which, the array and the single instance are instances of collection classes "room" {cCollector} which contains a collection of items, lets say called "stuff" {cCollection}, each of which item {cItem} is at this stage untyped (but maybe accessable as :object).

Class room::object()
contents:stuff
int contentcount();
object getFirst();
object getNext();

Class stuff::object()
int count();
object item(string objectname);
object getFirst();
object getNext();
...
However, this limits any instance of MyHouse to exactly 5 MyBedrooms, I cant upsize nor downsize.

MyKitchen is again limited to exactly one instance.  But they are all instances of the collection class "room".  This is the point I'm trying to make.  That, from the pov of the "house" class, it can only describe a building with exactly 5 bedrooms and 1 kitchen.

MODEL 2
anyHouse
houseRooms:rooms

where rooms is a collection class, cardinality 1 (from the anyhouse pov), and actual number of realrooms entirely dependent on run time instantiation.  So any house has a set of rooms, but the number of them is a run time aspect.

Class rooms
int roomCount();
room item(string roomname);
etc

bruce

"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.