2

I have these 2 structs and 1 class and I want to convert them into UML class:

struct cat
{
std::string name;
int id;
};

struct dog
{
std::string name;
std::string owner;
int age;
};

class Pet
{
std::vector<cat> cats;
std::vector<dog> dogs;
//some methods
};

i made this: class diagram thank you in advance

bruno
  • 32,421
  • 7
  • 25
  • 37
  • 2
    [Here](https://stackoverflow.com/questions/405953/generating-uml-from-c-code) You have an answer on a very similiar question. – sweak Mar 22 '21 at 16:56
  • 1
    out of the remark of @sweak (where the accepted answer of the similar question starts by a reference to my tool :-) ) if you learn UML I encourage you to first do by hand, so please edit your question with a proposal a class diagram and explain your problem (if you have). – bruno Mar 22 '21 at 17:02
  • i want to do it by hand but I can't see what's the link between Pet and the 2 other structs –  Mar 22 '21 at 17:17
  • @ben in *Pet* *cats* is a multi-valued property of type *cat*, so the type is *cat* and the multiplicity `*` or `0..*` if you prefer, and because of what a `std::vector` is you can also say the property is *ordered*, probably a cat is never duplicated in *cats* so you can also say the property is *unique* (refer to §9.5.4 of http://www.omg.org/spec/UML/2.5.1). Of course same about dog. Edit your question with a class diagram to check you understand well – bruno Mar 22 '21 at 17:23
  • done, so my question is: is it a composition or aggregation between Pet -> cat ? –  Mar 22 '21 at 17:43
  • @ben `done` : where ? add a link to your diagram in your question (I will make it visible, you do not have enough reputation to make it visible yourself). For your question about composition/aggregation in *Pet* you have vectors of instances, not vectors of pointer, so the instances in *cats* and *dogs* are deleted when the instance of *Pet* is deleted => composition – bruno Mar 22 '21 at 17:51
  • i did add a link but is this what are you looking for? –  Mar 22 '21 at 17:59
  • is it correct what i've made? –  Mar 22 '21 at 18:05

1 Answers1

1

Some remarks :

  • cat and dog are C++ struct => their members are public, not private
  • you missed to indicate the types of name, id, owner and age
  • you used associations navigable in the two directions, but a cat and a dog do not know the corresponding Pet
  • the association end must be named (cats / dogs), and it is useless to also show them through attributes

So, also adding the modifiers I speak about in the comments of your question :

enter image description here (I use cat/dog rather than Cat/Dog to follow the C++ code, but to use Cat/Dog is better)

bruno
  • 32,421
  • 7
  • 25
  • 37
  • @ben you welcome. Again, when you put a question include a proposal of solution in it, else people consider you do not made enough research effort and your question can be downvoted and closed without any answer. Good continuation on S.O. – bruno Mar 22 '21 at 18:35