{
    "componentChunkName": "component---src-templates-docs-js",
    "path": "/old/02-theory/design_object_diagram",
    "result": {"data":{"site":{"siteMetadata":{"title":"Linnéuniversitetet","language":"sv","courseCode":"1DV607"}},"mdx":{"fields":{"id":"d3aabeda-87d4-53ee-9352-a8fcce57bef1","title":"UML Object Diagram Notation","slug":"/old/02-theory/design_object_diagram"},"body":"var _excluded = [\"components\"];\n\nfunction _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"UML Object Diagram Notation\",\n  \"metaTitle\": \"UML Notation for Object Diagrams with Java Examples\",\n  \"metaDescription\": \"UML Notation for Object Diagrams with Java Examples\"\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, _excluded);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h1\", null, \"UML Object Diagram\"), mdx(\"p\", null, \"The UML object diagram shows the instances (objects) of classes at a particular time in the running application or system. They are a snapshot of the object structure at this particular point in time. They are commonly used to describe exactly how the objects are related at this time and what exact valuese they have. Object diagrams are particlularly usfull in describing the state of the application so that understanding and debugging of complicated situations in algorithms and structure.  \"), mdx(\"p\", null, \"They can be used as a precursor to a sequence diagram (that also shows objects), showing the state just as the sequence diagram behavior is starting and/or the state when the behavior has executed.\"), mdx(\"p\", null, \"Objects are shown with their type (class), attribute values with real data and possible links to other objects. The attributes and links are connected to the type (class) definition. I.e. the object cannot have links or attributes without the class defining them. The links are used to send messages and thus need to be formed for a sequence diagram to work.\"), mdx(\"h2\", null, \"Example\"), mdx(\"p\", null, \"Lets consider a small application consiting of one class. Two objects are created, and a link between them is formed as one recieves the other as a parameter in a method.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-java\"\n  }, \"\\nclass Person {\\n\\n\\n  boolean feelingGreat;\\n\\n\\n  Person(boolean feelingOfGreatness) {\\n\\n    feelingGreat = feelingOfGreatness;\\n\\n  }\\n\\n\\n  public void printFriendStatus(Person friend) {\\n\\n    // object diagram for this point in time\\n\\n    System.out.println(\\\"My friend is doing: \\\" + friend.howAreYou());\\n\\n  }\\n\\n\\n  public String howAreYou(Person friend) {\\n\\n    if (feelingGreat) {\\n\\n      return \\\"Great!\\\";\\n\\n    } else {\\n\\n      return \\\"not so good...\\\";\\n\\n    }\\n\\n  }\\n\\n\\n  public static void main(String[] args) {\\n\\n    Random r = new Random();\\n\\n    Person alice = new Person(r.nextBoolean());\\n\\n    Person john = new Person(r.nextBoolean());\\n\\n    alice.printFriendStatus(john);\\n\\n  }\\n\\n}\\n\\n\")), mdx(\"p\", null, \"In mermaid there is no dedicated diagram type for object diagrams, but the flowchart seems to be working ok (but notationwise not perfect, e.g. a missing line under the object:class name).\"), mdx(\"p\", null, \"Let us consider the situation where one object \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"alice\"), \" is feeling great and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"john\"), \" is not so good. At the moment when the method printFriendStatus is entered the object diagram would look like this:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-mermaid\"\n  }, \"\\n  flowchart LR\\n\\n    alice --friend--- john\\n\\n\\n    alice[alice:Person<br />feelingGreat=true]\\n\\n    john[john:Person<br />feelingGreat=false]\\n\\n    \\n\")), mdx(\"h2\", null, \"Reflexive Relation Example\"), mdx(\"p\", null, \"Object diagrams are particularly well suited to show examples of complex structures. Class diagrams can often become too simple or generic to provide the needed understanding.\"), mdx(\"p\", null, \"In this example we use a Diety class that can have either 0 or two parents which are also Dieties. The class diagram would look something like this.\"), mdx(\"p\", null, \"  classDiagram\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\"\n  }, \"Diety --> \\\"parents 0, 2\\\" Diety\\n\\nclass Diety {\\n  name: String\\n}\\n\")), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-mermaid\"\n  }, \"  classDiagram\\n    Diety --> \\\"parents 0, 2\\\" Diety\\n    class Diety {\\n      name: String\\n    }\\n\")), mdx(\"p\", null, \"The implementation could look something like this:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-java\"\n  }, \"\\npublic class Diety {\\n\\n  private String name;\\n\\n  Person[] parents;\\n\\n\\n  public void Diety(String name) {\\n\\n    this.name = name;\\n\\n  }\\n\\n\\n  public void Diety(String name, Diety parent1, Diety parent2) {\\n\\n    this.name = name;\\n\\n    parents = new Person[2];\\n\\n    parents[0] = parent1;\\n\\n    parents[1] = parent2;\\n\\n  }\\n\\n}\\n\\n  \\n\")), mdx(\"p\", null, \"While this looks simple enough quite complex structures can arise from this and often benefits from visualziation using object diagrams. Especially when manipulating the stucture in different ways.\"), mdx(\"h3\", null, \"Simple situation\"), mdx(\"p\", null, \"Lets just consider a simple situation implemented like this:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-java\"\n  }, \"\\npublic class App {\\n\\n  public static void main(String args) {\\n\\n    Diety god_of_thunder = new Diety(\\\"Tor\\\", new Diety(\\\"Odin\\\"), new Diety(\\\"Fjorgyn\\\"));\\n\\n  }\\n\\n}\\n\\n\")), mdx(\"p\", null, \"The object diagram provides a way to visualize this exact situation and when the objects have been created it should look like this:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-mermaid\"\n  }, \"\\n  flowchart LR\\n\\n    t ---- o\\n\\n    t ---- f\\n\\n\\n    t[god_of_thunder:Diety<br />name=Tor]\\n\\n    o[:Diety<br />name=Odin]\\n\\n    f[:Diety<br />name=Fjorgyn]\\n\\n    \\n\")), mdx(\"h3\", null, \"More complex\"), mdx(\"p\", null, \"Things can quicly become more complicated:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-java\"\n  }, \"\\npublic class App {\\n\\n  public static void main(String args) {\\n\\n    Diety god_of_thunder = new Diety(\\\"Tor\\\", new Diety(\\\"Odin\\\"), new Diety(\\\"Fjorgyn\\\"));\\n\\n    Diety godess_of_marriage = new Diety(\\\"Siv\\\");\\n\\n    Diety child1 = new Diety(\\\"Mode\\\", god_of_thunder, siv);\\n\\n    Diety child2 = new Diety(\\\"Trud\\\", god_of_thunder, siv);\\n\\n    Diety child3 = new Diety(\\\"Magne\\\", god_of_thunder, new Diety(\\\"J\\xE4rnsaxa\\\"));\\n\\n  }\\n\\n}\\n\\n\")), mdx(\"p\", null, \"The above situation can be visualzied using the following object diagram.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-mermaid\"\n  }, \"\\n  flowchart LR\\n\\n    t ---- o\\n\\n    t ---- f\\n\\n    mo ---- t\\n\\n    mo ---- s\\n\\n    tr ---- t\\n\\n    tr ---- s\\n\\n    ma ---- t\\n\\n    ma ---- j\\n\\n\\n    t[god_of_thunder:Diety<br />name=Tor]\\n\\n    o[:Diety<br />name=Odin]\\n\\n    f[:Diety<br />name=Fjorgyn]\\n\\n    mo[child1:Diety<br />name=Mode]\\n\\n    s[godess_of_marriage:Diety<br />name=Siv]\\n\\n    tr[child2:Diety<br />name=Trud]\\n\\n    ma[child3:Diety<br />name=Magne]\\n\\n    j[:Diety<br />name=J\\xE4rnsaxa]\\n\\n    \\n\")), mdx(\"h2\", null, \"Object Names\"), mdx(\"p\", null, \"As can be seen in the above the object names are not consistenly used. From a technical perspective every object has its uniqe identity i.e. the object name. However, this id is often not practical to use, instead it is common to a variable name as this maps more clearly to the actual implementation. The problem with this approach is that several variables can reference the same object. In the example above the variables \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"john\"), \" (local variable in main) and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"friend\"), \" (method parameter) actually referene the same object. Then you need to select the name that makes the most sense in the context of what you want to show, this could even be to use an attribute as the name. For example the object named \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"god_of_thunder\"), \" could likey be named \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Tor\"), \" instead, esp. since we likely do not want several dieties named Tor (though we technically are free to do this).\"), mdx(\"p\", null, \"It is also rather common to have anonymous objects, at least if the actual names are not that important. Though this can make the model harder to understand and connect to an actual scenario. It it advicet to use at least a few onbject names.\"), mdx(\"h2\", null, \"Link Names\"), mdx(\"p\", null, \"Link names are commonly not used, but it is an option to increase understanding of how the objects are linked. In the first example the objects are linked using the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"friend\"), \" parameter. Links can also have a directio if this is important to show. There can be a tendency to just repeat the names of roles in the class diagram, and if so it makes little sense to add the link name.\"), mdx(\"p\", null, \"However, link names are often needed if you have several link between objects of the same type so that you can know what object is linked using for the different roles. For example consider a Car class that has both an owner and a driver. The class diagram would look like this:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-mermaid\"\n  }, \"  classDiagram\\n    direction LR\\n    Car --> \\\"driver\\\" Person\\n    Car --> \\\"owner\\\" Person\\n    class Person {\\n      name: String\\n    }\\n\")), mdx(\"p\", null, \"Implemented like this.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-java\"\n  }, \"\\n  public class Car {\\n\\n    private Person driver;\\n\\n    private Person owner;\\n\\n    ...\\n\\n  }\\n\\n\\n  public class Person {\\n\\n    private String name;\\n\\n    ...\\n\\n  }\\n\\n\\n\")), mdx(\"p\", null, \"In this case it becomes important to use link names to know what the actual different links mean. Compare the two following object diagrams and you see that using link names is needed. In the first one we dont know which of the objects is the owner and which is the driver. \"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-mermaid\"\n  }, \"\\n  flowchart LR\\n\\n    j ---- c\\n\\n    a ---- c\\n\\n\\n    j[john:Person<br />name=John]\\n\\n    a[alice:Person<br />name=Alice]\\n\\n    c[abc123:Car]\\n\\n    \\n\")), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-mermaid\"\n  }, \"\\n  flowchart LR\\n\\n    j --driver---- c\\n\\n    a --owner---- c\\n\\n\\n    j[john:Person<br />name=John]\\n\\n    a[alice:Person<br />name=Alice]\\n\\n    c[abc123:Car]\\n\\n    \\n\")), mdx(\"p\", null, \"An alternative can be to use object names, but this approach would not work if we have a more complex model.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-mermaid\"\n  }, \"\\n  flowchart LR\\n\\n    j ---- c\\n\\n    a ---- c\\n\\n    j ---- c2\\n\\n\\n    j[?:Person<br />name=John]\\n\\n    a[owner:Person<br />name=Alice]\\n\\n    c[abc123:Car]\\n\\n    c2[adb456:Car]\\n\\n    \\n\")), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-mermaid\"\n  }, \"\\n  flowchart LR\\n\\n    j --driver---- c\\n\\n    a --owner---- c\\n\\n    j --owner---- c2\\n\\n\\n    j[john:Person<br />name=John]\\n\\n    a[alice:Person<br />name=Alice]\\n\\n    c[abc123:Car]\\n\\n    c2[adb456:Car]\\n\")));\n}\n;\nMDXContent.isMDXComponent = true;","tableOfContents":{"items":[{"url":"#uml-object-diagram","title":"UML Object Diagram","items":[{"url":"#example","title":"Example"},{"url":"#reflexive-relation-example","title":"Reflexive Relation Example","items":[{"url":"#simple-situation","title":"Simple situation"},{"url":"#more-complex","title":"More complex"}]},{"url":"#object-names","title":"Object Names"},{"url":"#link-names","title":"Link Names"}]}]},"parent":{"relativePath":"old/02-theory/design_object_diagram.md"},"frontmatter":{"metaTitle":"UML Notation for Object Diagrams with Java Examples","metaDescription":"UML Notation for Object Diagrams with Java Examples","fullWidth":null}},"allMdx":{"edges":[{"node":{"fields":{"slug":"/forelasningar-2026","title":"Föreläsningar 2026"}}},{"node":{"fields":{"slug":"/","title":"Objektorienterad analys och design med UML (1DV607)"}}},{"node":{"fields":{"slug":"/laborationer-2026","title":"Laborationer 2026"}}},{"node":{"fields":{"slug":"/old","title":"Old"}}},{"node":{"fields":{"slug":"/forelasningar-2026/00-tema-2-objektorienterad-analys-och-uml","title":"Tema 2 – Objektorienterad analys och modellering med UML"}}},{"node":{"fields":{"slug":"/forelasningar-2026/00-tema-3-objektorienterad-design-med-uml","title":"Tema 3 – Objektorienterad design med UML"}}},{"node":{"fields":{"slug":"/forelasningar-2026/01-kursintroduktion-och-domanmodellering","title":"1. Kursintroduktion och domänmodellering"}}},{"node":{"fields":{"slug":"/forelasningar-2026/02-objektorienterad-analys-och-modellering","title":"2. Objektorienterad analys och modellering"}}},{"node":{"fields":{"slug":"/forelasningar-2026/03-uml-modellering","title":"3. Fortsatt modellering med UML"}}},{"node":{"fields":{"slug":"/forelasningar-2026/04-grasp","title":"4. GRASP"}}},{"node":{"fields":{"slug":"/forelasningar-2026/00-tema-1-grunderna","title":"Tema 1 – Grunderna i objektorienterad analys och design"}}},{"node":{"fields":{"slug":"/laborationer-2026/01-laboration-1","title":"Laboration 1 – Domänmodellering"}}},{"node":{"fields":{"slug":"/old/001-introduction","title":"Course Introduction"}}},{"node":{"fields":{"slug":"/old/01-information","title":"Course Information"}}},{"node":{"fields":{"slug":"/laborationer-2026/02-laboration-2","title":"Laboration 2"}}},{"node":{"fields":{"slug":"/old/02-theory","title":"Theory"}}},{"node":{"fields":{"slug":"/old/03-assignments","title":"Assignments"}}},{"node":{"fields":{"slug":"/old/01-information/01-welcome","title":"Welcome to the Course"}}},{"node":{"fields":{"slug":"/old/01-information/registration","title":"Course Registration"}}},{"node":{"fields":{"slug":"/old/02-theory/01-intro_to_ooad","title":"Introduction to Object Oriented Analysis and Design"}}},{"node":{"fields":{"slug":"/old/01-information/grading","title":"Course Grading"}}},{"node":{"fields":{"slug":"/old/02-theory/03_software_architecture","title":"Software Architecture"}}},{"node":{"fields":{"slug":"/old/02-theory/04_mvc","title":"Model View Controller"}}},{"node":{"fields":{"slug":"/old/02-theory/02-domain_modeling","title":"Domain Modeling"}}},{"node":{"fields":{"slug":"/old/02-theory/06_grasp1","title":"GRASP 1"}}},{"node":{"fields":{"slug":"/old/02-theory/05_layers_components","title":"Layers & Components"}}},{"node":{"fields":{"slug":"/old/02-theory/07_grasp2","title":"GRASP 2"}}},{"node":{"fields":{"slug":"/old/02-theory/09_gof1","title":"GoF 1"}}},{"node":{"fields":{"slug":"/old/02-theory/10_gof2","title":"GoF 2"}}},{"node":{"fields":{"slug":"/old/02-theory/11_solid","title":"SOLID"}}},{"node":{"fields":{"slug":"/old/02-theory/08_grasp3","title":"GRASP 3"}}},{"node":{"fields":{"slug":"/old/02-theory/design_class_diagram","title":"UML Design Class Notation"}}},{"node":{"fields":{"slug":"/old/02-theory/design_class_relations","title":"UML Design Class Relations"}}},{"node":{"fields":{"slug":"/old/02-theory/design_object_diagram","title":"UML Object Diagram Notation"}}},{"node":{"fields":{"slug":"/old/02-theory/99-exercises","title":"Exercises"}}},{"node":{"fields":{"slug":"/old/02-theory/design_package_diagram","title":"UML Package Notation"}}},{"node":{"fields":{"slug":"/old/02-theory/domain_class_diagram","title":"UML Domain Model"}}},{"node":{"fields":{"slug":"/old/02-theory/reading-instructions","title":"Reading Instructions"}}},{"node":{"fields":{"slug":"/old/03-assignments/01-assignment_1","title":"Assignment 1"}}},{"node":{"fields":{"slug":"/old/03-assignments/02-assignment_2","title":"Assignment 2"}}},{"node":{"fields":{"slug":"/old/03-assignments/03-assignment_3","title":"Assignment 3"}}},{"node":{"fields":{"slug":"/old/03-assignments/04-yahtzee","title":"Yahtzee Assignment"}}},{"node":{"fields":{"slug":"/old/old_template/ovningsuppgifter-del-a","title":"Övningsuppgifter del A"}}},{"node":{"fields":{"slug":"/old/old_template/ovningsuppgifter-del-b","title":"Övningsuppgifter del B"}}},{"node":{"fields":{"slug":"/old/03-assignments/01-assignment_1/lending-system-problem-description","title":"Stuff Lending System Problem Description"}}},{"node":{"fields":{"slug":"/old/03-assignments/01-assignment_1/yacht-club-problem-description","title":"Yacht Club Problem Description"}}},{"node":{"fields":{"slug":"/old/old_template/videologgar","title":"Vlog"}}},{"node":{"fields":{"slug":"/old/old_template/codeblock/1-index","title":"Sub Page"}}},{"node":{"fields":{"slug":"/old/03-assignments/02-assignment_2/test_specification","title":"Test Specification"}}},{"node":{"fields":{"slug":"/old/old_template/codeblock","title":"Syntax Highlighting"}}},{"node":{"fields":{"slug":"/old/old_template/ovningsuppgifter-del-a/01-hello-world","title":"Hello world"}}},{"node":{"fields":{"slug":"/old/old_template/ovningsuppgifter-del-a/02-simple-addition","title":"Enkel addition"}}}]}},"pageContext":{"id":"d3aabeda-87d4-53ee-9352-a8fcce57bef1"}},
    "staticQueryHashes": ["253607798","3706406642","710574383"]}