What is an Object Graph and how can it be implemented in my JavaScript code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dseals22
    New Member
    • Jan 2017
    • 74

    What is an Object Graph and how can it be implemented in my JavaScript code

    Hello Everyone,
    I am working on a creating an instance of a class in JavaScript using Object-Oriented skills. The question I have is how can I implement an object graph with using the code that I have so far in my JavaScript file? Here is my code so far.
    Code:
     function Person(Name, Grade, Gender, GPA, ClassRank)
        { 
             this.Name= name;
        **** this.Grade  = grade;
        **** this.Gender = gender;
        **** this.GPA = gpa;
        ***  this.ClassRank = classRank;
        }
        var student1= new Person("Gray", 'B', 'F', 3.34, 5);
        var student2= new Person("Jerry", 'A', 'M', 3.99, 4); 
    
        document.getElementById("demo1").innerHTML= student1.Name + " " + student1.Grade + "* " + student1.Gender + *" "* + student1.GPA + " " + student1.classRank; 
    
      document.getElementById("demo2").innerHTML= student2.Name + " " + student2.Grade + "* " + student2.Gender + *" "* + student2.GPA + " " + student2.classRank;
    Code:
     <html> 
        <head>
        <title></title>
        </head>
        <body>
        <p id= "demo1"> </p>
        <p id= "demo2"></p>
        </body>
        </html>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    The question I have is how can I implement an object graph
    what do you consider an 'object graph'?

    Comment

    • dseals22
      New Member
      • Jan 2017
      • 74

      #3
      @Dormilich,

      When you link two different objects together.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        and what should that look like, HTML-wise?

        Comment

        • dseals22
          New Member
          • Jan 2017
          • 74

          #5
          @Dormilich I guess I could just get rid of the class names and just use the external JS file to show the JavaScript objects in the HTML page. How do I link the objects together though. Object graph is all about making the objects interact with one another. All I am question is this possible to do in JavaScript? How can it be done?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            How do I link the objects together though.
            the most simple thing were to set one object as a property of the other. But you can use any design pattern you want, if it works for you.

            Comment

            • dseals22
              New Member
              • Jan 2017
              • 74

              #7
              @Dormilich How would I do that? Any examples. I just want to master making the objects interact with each other.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                Code:
                var foo = {
                  a: 1
                };
                
                var bar = {
                  b: 2
                };
                
                bar.f = foo;

                Comment

                • dseals22
                  New Member
                  • Jan 2017
                  • 74

                  #9
                  @Dormilich So bar is now equal to foo? This is the structure that I think I was looking for.

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    So bar is now equal to foo?
                    bar.f is identical to foo. there would be no point in having foo and bar referencing the same object.

                    Comment

                    • dseals22
                      New Member
                      • Jan 2017
                      • 74

                      #11
                      @Dormilich This would be a simple example of an object graph? How could I get my two objects to link together?
                      Last edited by dseals22; Feb 28 '17, 04:57 PM. Reason: Too little answer

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        This would be a simple example of an object graph?
                        Not as I understand an object graph:

                        An object graph is a view of an object system at a particular point in time.

                        Comment

                        • dseals22
                          New Member
                          • Jan 2017
                          • 74

                          #13
                          @Dormilich I guess most people are not that familiar with it in JavaScript. For example,
                          var object1 = {};
                          var object2 = {};
                          object1.next = object2;

                          These two objects are identical to each other, right? But how can make my objects identical to each other?

                          Comment

                          • Dormilich
                            Recognized Expert Expert
                            • Aug 2008
                            • 8694

                            #14
                            These two objects are identical to each other, right?
                            no .

                            Comment

                            • dseals22
                              New Member
                              • Jan 2017
                              • 74

                              #15
                              @Dormilich why not? Can you please explain why it's not correct logic?

                              Comment

                              Working...