grouping variables of different type Java Requirement -


scenario :

class graph{     // many variables      node masteruser;     node masterfilter;     node masterlocation;      index indexuser;     index indexfilter;      graph() {         // initialize variables here     } }   // subclass  class myclass{      graph graph = new graph();      // can refer class members of graph class here graph object  } 

what happening when graph. members accessible.

but want group variables of class graph such

when user graph.index. index accessible. when user graph.nodes. nodes accessible.

how can it?

that's interfaces for.

interface graphnodes {             public node getmasteruser();     public node getmasterfilter();     public node getmasterlocation(); }  interface graphindexes {     public index getindexuser();     public index getindexfilter(); }  class graph implements graphnodes, graphindexes {     private node masteruser;     private node masterfilter;     private node masterlocation;     private index indexuser;     private index indexfilter;      public graphnodes getnode() { return this; }     public graphindexes getindex() { return this; }      public node getmasteruser() { return this->masteruser; }     public node getmasterfilter() { return this->masterfilter; }     public node getmasterlocation() { return this->masterlocation; }     public index getindexuser() { return this->indexuser; }     public index getindexfilter() { return this->indexfilter; } } 

now if have instance of graph class, , write:

graph graph = new graph(); graph.getindex()./* ... */ 

you able access getter methods indexes, , if type

graph.getnode()./* ... */ 

you can access nodes.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -