M
MRe
Hi,
This is probably more a design than programming question, but I
can't find a Java group for that[?]
I have a class that is private within a package, but contains a
nested class that I want to be public outside the package, i.e.
Outside the package, the non-nested class cannot be touched, but the
nested class can. This nested class is accessed by asking another
public class in the package to return it
Is this possible? (More detail below, if that doesn't make sense)
Thank you,
Kind regards,
Eliott
--More detail as promised--
If I have a package-private class called 'DataSet', and nested in
DataSet, a public class 'Stats', and in another file, a package-public
class 'Graph', that could return objects of type DataSet.Stats, I
would want, outside the package to say..
DataSet.Stats stats = graph.getStats();
But this doesn't compile, instead saying that DataSet cannot be
found; which seems simple enough, I can't always do whatever I want!
But is it that simple. Or is there some little [or big] thing I can do
to do what I want to do?
I know I could fix it by factoring the nested Stats part out of
DataSet, but it just feels right nested in DataSet
--Pseudo Java outline of the code--
// A class for displaying a graph
// and some stats in an app
package App
public class GraphPane
{ Graphables.Graph graph;
public void show()
{ Graphables.DataSet.Stats stats;
stats = graph.getStats();
}
}
// A package that embodies graphness
package Graphables;
// A graph with a set of data
public class Graph
{ DataSet dataSet;
public Graphables.DataSet.Stats getStats()
{ return dataSet.getStats();
}
}
// A set of data; in a package-private class
// Don't want the data outside, as only the
// Graph is to know about it
class DataSet
{ Stats stats;
float[] data;
public Graphables.DataSet.Stats getStats()
{ return stats;
}
// Stats (which, in my graphable world) are
// tightly linked with DataSet, and exist
// within data, but is also something that I
// need visible outside the package, because
// the graph doesn't show them
public class Stats
{ float calcMean()
{ float mean = 0;
for(float datum : data)
mean += datum;
return mean /= data.length;
}
}
}
Thanks again; for reading this far
This is probably more a design than programming question, but I
can't find a Java group for that[?]
I have a class that is private within a package, but contains a
nested class that I want to be public outside the package, i.e.
Outside the package, the non-nested class cannot be touched, but the
nested class can. This nested class is accessed by asking another
public class in the package to return it
Is this possible? (More detail below, if that doesn't make sense)
Thank you,
Kind regards,
Eliott
--More detail as promised--
If I have a package-private class called 'DataSet', and nested in
DataSet, a public class 'Stats', and in another file, a package-public
class 'Graph', that could return objects of type DataSet.Stats, I
would want, outside the package to say..
DataSet.Stats stats = graph.getStats();
But this doesn't compile, instead saying that DataSet cannot be
found; which seems simple enough, I can't always do whatever I want!
But is it that simple. Or is there some little [or big] thing I can do
to do what I want to do?
I know I could fix it by factoring the nested Stats part out of
DataSet, but it just feels right nested in DataSet
--Pseudo Java outline of the code--
// A class for displaying a graph
// and some stats in an app
package App
public class GraphPane
{ Graphables.Graph graph;
public void show()
{ Graphables.DataSet.Stats stats;
stats = graph.getStats();
}
}
// A package that embodies graphness
package Graphables;
// A graph with a set of data
public class Graph
{ DataSet dataSet;
public Graphables.DataSet.Stats getStats()
{ return dataSet.getStats();
}
}
// A set of data; in a package-private class
// Don't want the data outside, as only the
// Graph is to know about it
class DataSet
{ Stats stats;
float[] data;
public Graphables.DataSet.Stats getStats()
{ return stats;
}
// Stats (which, in my graphable world) are
// tightly linked with DataSet, and exist
// within data, but is also something that I
// need visible outside the package, because
// the graph doesn't show them
public class Stats
{ float calcMean()
{ float mean = 0;
for(float datum : data)
mean += datum;
return mean /= data.length;
}
}
}
Thanks again; for reading this far