What is the difference between a Class Diagram vs an Object Diagram? [closed]
Asked Answered
J

2

28

What is the difference between Class Diagram and Object Diagram?

Jer answered 9/10, 2013 at 21:7 Comment(2)
A class diagram shows your classes and their relationships. An object diagram shows the interactions between objects at some point during run time.Enarthrosis
Diagrams are above programming languages, this belongs on programmers.stackexchange.com. Have you googled the two explanations? What wasn't clear about it? This will probably get closed for not showing any effort and/or being off topic.Pechora
D
16

Wikipedia gives examples of both: Class Diagram Object Diagram

The differences are in the purpose, and what they show.

A Class Diagram will show what the Objects in your system consist of (members) and what they are capable of doing (methods).

In contrast, an Object Diagram will show how objects in your system are interacting with each other at some point in time, and what values those objects contain when the program is in this state.

Dulse answered 9/10, 2013 at 21:12 Comment(4)
“how objects in your system are interacting with each other at some point in time”: is there a way to link this to activity diagrams and/or state machine diagrams?Yeasty
They really serve different purposes... I'm not sure what benefit there would be, but you could think of the Object Diagram as a particular state in a state machine diagram, I suppose...Dulse
Object diagrams provide a static view while activity and state diagrams provide a dynamic view. In my experience, object diagrams are not used very often, but if your have complex relations between classes that are best shown by an example object network, object diagrams are the right way to visualize such an object network.Chilopod
Wikipedia is just wrong. An object diagram does not describe interactions. There are two types of UML2.5 diagrams: behavior diagrams (which describe interactions) and structure diagrams (describe structures, object diagrams are here); object diagrams are not part of behavior diagrams. Object diagrams are useful to describe instances in a specific configuration: e.g. describing the state of a state machine. But not interactions. To describe interactions, better use a behavior diagram (uml-diagrams.org/uml-25-diagrams.html).Adolpho
M
34

As specified in the UML specifications:

class diagram is a graph of Classifier elements connected by their various static relationships. Note that a “class” diagram may also contain interfaces, packages, relationships, and even instances, such as objects and links. Perhaps a better name would be “static structural diagram”, but “class diagram” is shorter and well established.

object diagram

is a graph of instances, including objects and data values. A static object diagram is an instance of a class diagram; it shows a snapshot of the detailed state of a system at a point in time. The use of object diagrams is fairly limited, mainly to show examples of data structures.


In simple words...

Class diagram shows a collection of declarative (static) model elements, such as classes, types, and their contents and relationships.

Object diagram encompasses objects and their relationships at a point in time. It may be considered a special case of a class diagram or a collaboration diagram.


class diagram

enter image description here

object diagram

enter image description here

A good powerpoint to start with: http://people.bu.edu/rfv/SC511/downloads/uml.ppt

Mai answered 9/10, 2013 at 21:11 Comment(1)
What are "Classifier elements" when they're at home, then?Epilogue
D
16

Wikipedia gives examples of both: Class Diagram Object Diagram

The differences are in the purpose, and what they show.

A Class Diagram will show what the Objects in your system consist of (members) and what they are capable of doing (methods).

In contrast, an Object Diagram will show how objects in your system are interacting with each other at some point in time, and what values those objects contain when the program is in this state.

Dulse answered 9/10, 2013 at 21:12 Comment(4)
“how objects in your system are interacting with each other at some point in time”: is there a way to link this to activity diagrams and/or state machine diagrams?Yeasty
They really serve different purposes... I'm not sure what benefit there would be, but you could think of the Object Diagram as a particular state in a state machine diagram, I suppose...Dulse
Object diagrams provide a static view while activity and state diagrams provide a dynamic view. In my experience, object diagrams are not used very often, but if your have complex relations between classes that are best shown by an example object network, object diagrams are the right way to visualize such an object network.Chilopod
Wikipedia is just wrong. An object diagram does not describe interactions. There are two types of UML2.5 diagrams: behavior diagrams (which describe interactions) and structure diagrams (describe structures, object diagrams are here); object diagrams are not part of behavior diagrams. Object diagrams are useful to describe instances in a specific configuration: e.g. describing the state of a state machine. But not interactions. To describe interactions, better use a behavior diagram (uml-diagrams.org/uml-25-diagrams.html).Adolpho

© 2022 - 2024 — McMap. All rights reserved.