V. basic class diagrams uml question

i’m reading a uml book (uml demystified) and thought it was all making sense but now i come to try and actually use it, i now realise not so.

class diagrams. i know what a class and an instance of a class is basically about in oop (mainly from objective-c). in uml most class diagrams have mainly classes in. i know that shouldn’t be surprising given the name of these diagrams, class diagrams, but given what i know about oop the preponderance of classes and the absence of instances in the diagrams seems odd to me.

a typical v. simple uml class diagram:


+-------------+           +-------------+
|      A      |           |      B      |
+-------------+           +-------------+
|             | --------> |             |
+-------------+ 1       1 +-------------+
|             |           |             |
+-------------+           +-------------+

what is that actually saying?:

  • the class (and i mean the class, not an instance of) A has a variable/pointer to the class B?
  • an instance of class A has a pointer to an instance of class B?

it must mean classes not instances because there is a way of representing instances, so if it had meant an instance of A should have a pointer to an instance of B it’d have used the instance symbol (a box split horizontally in two by a line rather than split into three). but classes are one off, and have global scope… and hang on though, come to think of it, there are diagrams like this:


+-------------+           +-------------+
|      A      |           |      B      |
+-------------+           +-------------+
|             | --------> |             |
+-------------+ 1     1…* +-------------+
|             |           |             |
+-------------+           +-------------+

meaning one A, and one or more B’s. so it must mean instances? you can’t have more than one class of the same type – classes are one offs right?, and instances obviously aren’t. so if it does mean instances why are they using class symbols and what are the instance symbols for?

confused :confused: the book doesn’t seem to tackle what i’m asking about at all. not very good.

thanks.

another go, from a slightly different angle…


+-------------+           +-------------+
|      A      |           |      B      |
+-------------+           +-------------+
|             | --------> |             |
+-------------+ 1     1…* +-------------+
|             |           |             |
+-------------+           +-------------+

the above appears in a uml book, so i assume it’s correct/valid.

the boxes represent classses. so there’s one class A and one or more class B’s. how can you have more than one of the same class? you can have many instances of a class but these aren’t instances, they’re classes. so what’s going on there?

if the name is underlined, then it has classifier scope, otherwise it is a instance. just my best guess, it might as well be a mistake (search for errata in a later edition of the book if available)

thanks, i’ve found the answer. the box compartmented into three sections is representing a class, but the multiplicity indicators (“1”, “*”, etc.) are talking about objects (instances of the class). obviously objects are generated from/by classes. so the box is a class but the multiplicity values are about objects from that class. it was that merged dual meaning which was unclear to me. i thought it should be either an object or a class but it’s kind of both at the same time.

i was partly confused more so because the main oop language i know a bit about, but not that much, is objective-c, and in that (not sure how similar or different this is to other languages) classes can behave very much like objects/instances in a lot of ways, e.g. you can have a pointer to a class and you can pass that pointer round, like as a parameter of a method call for example. so classes can be like instances/objects in a lot of ways. but that isn’t what the standard uml class diagram i repeated above is talking about at all.