Author Topic: Object, class in a class diagram  (Read 1756 times)

JEff Russell

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Object, class in a class diagram
« on: April 11, 2003, 11:39:36 am »
Probably a simple question:
What differentiates an "object" and a "class" in EA's class diagram toolbox? Why isn't an "object" some sort of stereotype?
What kinds of relationships might be used with an "object"?

Super-duper-newbie,
JEff

fwoolz

  • EA User
  • **
  • Posts: 435
  • Karma: +0/-0
  • We have met the enemy, and he is us.<Pogo, 1970>
    • View Profile
Re: Object, class in a class diagram
« Reply #1 on: April 11, 2003, 12:06:22 pm »
Hello Jeff,

Well, objects are class instances, and are shown in UML differently than classes.  Unless you're creating "ad hoc" objects on a diagram without an underlying class definition, IMHO it's better to drag and drop an already defined class (with Auto Instance turned on) onto a diagram to create an object.  However, it's also possible to drag an object from the pallette onto a diagram, give it a name, then set its classifier (maybe at a later time) to refer to an existing class.

Objects support basically the same relationships as classes.

Hope this helps...

Cheers,
Fred Woolsey
Fred Woolsey
Interfleet Technology Inc.

Always be ready to laugh at yourself; that way, you beat everyone else to the punch.


JEff Russell

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: Object, class in a class diagram
« Reply #2 on: April 11, 2003, 01:16:48 pm »
Fred,
Thanks for the comments. I guess I should be using classes, as I am looking to create an "ad hoc" class diagram. I am applying the ideas from Rosenberg's "Use Case Driven Object Modeling...". He suggests a high-level domain analysis before starting Use Cases, to sort out the domain vocabulary. I would think this leads to a rather abstract description of the objects in the problem domain (which might or might not resemble the "real" set of classes used in the system).  
The real confusion started because EA objected to setting an inheritance relationship between objects.  I had interpreted generalization relationships between problem domain objects to be something slightly different than the inheritance relationship between classes, since inheritance is just one way to implement generalization.  
(Do you buy that last point?)

JEff
JEff

fwoolz

  • EA User
  • **
  • Posts: 435
  • Karma: +0/-0
  • We have met the enemy, and he is us.<Pogo, 1970>
    • View Profile
Re: Object, class in a class diagram
« Reply #3 on: April 11, 2003, 06:52:30 pm »
Hi Jeff,

Lessee... UML 1.5 spec shows no examples of inheritance in object relationships... however, a dependency relationship and a stereotype could be used to make the inheritance relationship clear.  Certainly, if classes are linked with an inheritance relationship, the methods of the base class are inherited by object instances of the derived class; these can be "invoked" in collaboration diagrams.  But at the high-level, abstract view you're describing, I would think "ad hoc" objects and associations (directed or otherwise) would suffice, since relationships such as inheritance should, again IMHO, be left until the object vocabulary has been defined.

Cheers,
Fred Woolsey
Fred Woolsey
Interfleet Technology Inc.

Always be ready to laugh at yourself; that way, you beat everyone else to the punch.


mbc

  • EA User
  • **
  • Posts: 237
  • Karma: +1/-0
  • Embedded software developer
    • View Profile
Re: Object, class in a class diagram
« Reply #4 on: April 15, 2003, 02:29:33 am »
Hi Jeff

"Classes" and "objects" are 2 different things. The meaning of the words are not related to whether they are used in the context of analysis modelling or design modelling.

This is from the UML spec:
A class is the descriptor for a set of objects with similar structure, behavior, and relationships.
An object represents a particular instance of a class. It has identity and attribute values.

IMO it doesn't really make sense to have an inheritance relationship between objects, because objects are what they are.

I will give you a simple example:

We could have a class called "Human" in our analysis model, which contains attributes such as e.g. birth date, height, weight, name, etc. Note that these attribute do not have values in the class. I.e. the class "Human" cannot have a specific birth date or height.

Then we make 2 classes called "Man" and "Woman". They both have inheritance relationships to "Human", because they are specializations of "Human". Each of the 2 classes could then have attributes that relate specifically to men or women respectively.

Then we instantiate "Man", i.e. we create an object of class "Man". We set the "name" attribute of that object to "Jeff". The object with name="Jeff" does not have an inheritance relationship to the class "human", but its classifier ("Man") does.

When you are doing your domain analysis modelling, you'll want to describe concepts of your problem domain in general (=classes). At that point you are not interested in specific, individual things (=objects).

Objects are suitable for modelling something specific, such as a specific person opening a specific file and printing it on a specific printer. Some people like to start with a specific case like this, and then use it as a guide to identify classifiers afterwards. E.g., maybe you know about "Jeff" wanting to open "account.xls" and printing it on "HP Laserjet". From that model of instances you can then say to yourself: "Oh, I think I need the classes "Accountant", "Spreadsheet file" and "Printer".

Personally I mostly use objects when I model interactions, i.e. in sequence diagrams and collaboration diagrams. Messages are passed between objects, not between classes, because classes are not things that actually exist. A class describes common characteristics of objects that actually exist.

I'll tell you briefly what I do:
My Analysis Model contains classes that represent real-world concepts from the problem domain. Often those classes also appear as nouns in my use cases.
When I find it necessary, I create some sample interactions between instances (objects) of those classes. The interaction diagrams help me clarify the problem in my mind.
My Design Model contains classes that will exist in the software implementation. Often these classes are taken from or at least inspired by classes in the Analysis Model. I create interactions between instances (objects) of the software classes to establish what relations are needed. Or I create a sequence diagram from a use case in order to establish what classes are needed. Still, the interaction take place between instances (objects), not classes.

This turned out quite a bit longer than I planned, and it may be too basic for you,  but it just seemed that you had classes and objects a bit confused. I hope this could help you.

Mikkel

fwoolz

  • EA User
  • **
  • Posts: 435
  • Karma: +0/-0
  • We have met the enemy, and he is us.<Pogo, 1970>
    • View Profile
Re: Object, class in a class diagram
« Reply #5 on: April 16, 2003, 06:31:49 pm »
MBC,

Agreed...  it doesn't make sense to define relationships between objects; these need to be done between the underlying classes.  However, relationships do exist between objects, including inheritance (otherwise, how could inherited methods be called from a derived class?).  So I would say that there is a real sense in which the inheritance relationship between classes passes to the objects instantiated from those classes.  You could look at a family tree & will as defining "inheritance" between sire and scion, but the estate goes to the scion (object), not to the document (class).  Classes have no real (read "concerete") existence until objects are created from those classes, Plato notwithstanding.  I'm not quibbling, just philosophizing.

Cheers,
Fred Woolsey
Fred Woolsey
Interfleet Technology Inc.

Always be ready to laugh at yourself; that way, you beat everyone else to the punch.


PhilR

  • EA User
  • **
  • Posts: 87
  • Karma: +0/-0
    • View Profile
Re: Object, class in a class diagram
« Reply #6 on: April 16, 2003, 06:36:39 pm »
I use object diagrams when I work with users.  I have found over many years that the average person has great difficulty working with an abstract concept such as a "class".

Rather than Human, Man, Woman etc I use Fred, Bill, Mary... when I am working on a white board with users.  I then convert these into Classes "behind the scenes".

Naturally we normally work with much more difficult concepts than the above.  And that is where this approach has real benefits.

I also use object links liberally to help identify associations.  Even the people who get the idea of classes usually stumble over associations.

PhilR

JEff Russell

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: Object, class in a class diagram
« Reply #7 on: April 17, 2003, 06:56:16 am »
PhilR,
I think your mention of object/class faimiliarity was where I started from, being relatively new to OO stuff.  I thought starting with objects and then converting things to classes (when they were discovered) would help. After a day or so, that step wasn't so important (for me).

So, PhilR, when you are throwing around objects in a tool like EA, do you draw relationships? What type to you use? (This whole problem started with me trying to draw an inheritance link between objects---which, I agree, was silly.)  I would think a general "Association" link with a text label like "is a" or "has a" would help non-UML types more than squares and arrows.

JEff
JEff

PhilR

  • EA User
  • **
  • Posts: 87
  • Karma: +0/-0
    • View Profile
Re: Object, class in a class diagram
« Reply #8 on: April 18, 2003, 07:53:51 pm »
JEff,

To be honest I never draw object diagrams in EA.  They remain forever white board dumps which I then convert to class diagrams.  I gusess if the suers wanted a "prettied up" version I would draw one but I always discourage this.

PhilR

PhilR

  • EA User
  • **
  • Posts: 87
  • Karma: +0/-0
    • View Profile
Re: Object, class in a class diagram
« Reply #9 on: April 18, 2003, 07:54:55 pm »
I meant users not "suers".  Interpret this slip as you will  ;D

fwoolz

  • EA User
  • **
  • Posts: 435
  • Karma: +0/-0
  • We have met the enemy, and he is us.<Pogo, 1970>
    • View Profile
Re: Object, class in a class diagram
« Reply #10 on: April 19, 2003, 09:44:01 am »
Good one, Phil!  Hope you always have "users," never "suers!"

Cheers,
Fred Woolsey
Fred Woolsey
Interfleet Technology Inc.

Always be ready to laugh at yourself; that way, you beat everyone else to the punch.