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.
node
s 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
Post a Comment