Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>EDIT -- this answer is for a previous version of the question, that does not include anything about clients and multiple servers. This answer is about sharing data between instances of classes.</p> <p>There are many ways to do something like this. If I understood your approach outlined in the first paragraph, you dont want class1 and class2 to extend class3. You want them to both have a reference to <em>the same instance</em> of class3. If they share a reference to the same object, then changing values on that object will be reflected in both classes. If they extend class3, like you said you tried, then both class1 and class2 will have the properties of class3, but they wont be sharing any data. If class 3 had a property</p> <pre><code> Object value; </code></pre> <p>then <em>instances</em> of class1 and class2 would have separate references to separate instances of 'value'.</p> <p>You need to undertand the relationship between a class, and object instance, and what extending a class means. </p> <p>Note that this is not really a good way to share information between objects in a real program. You can run into all sorts of concurrency issues. The same is true for a solution that used a global mechanism implemented using static fields. </p> <p>To do this with static fields do something like:</p> <pre><code>class SharedData { public static Object shared1; } </code></pre> <p>and then in your class1 and class2 instances you can access</p> <pre><code>SharedData.shared1 </code></pre> <p>for either set or get.</p> <p>But I would not do anything like this in any sort of professional context.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload