More Inner class debate

  • Thread starter Christian Bongiorno
  • Start date
C

Christian Bongiorno

I am at a point where it seems that an inner-inner class is in order
for what I am working on.

public class A {

private class B {

private class C {

}
}
}


Would this be considered bad form? If so, I have to make B a public
outter class eventhough I want to control the construction of B by
it's caller. If it's a private inner class, only the outter class can
construct it.

In other words, I only want A to be able to instantiate B, and B to
instantiate C

Christian
http://home.stny.rr.com/cbongior/resume/resume.PDF
 
S

Stefan Schulz

I am at a point where it seems that an inner-inner class is in order
for what I am working on.

public class A {

private class B {

private class C {

}
}
}


Would this be considered bad form? If so, I have to make B a public
outter class eventhough I want to control the construction of B by
it's caller. If it's a private inner class, only the outter class can
construct it.

In other words, I only want A to be able to instantiate B, and B to
instantiate C

Would it be absolutely impossible to make class B a toplevel type, without
the public modifier (making it package-private?) This way you avoid making
an inner-inner class, and at the same time "hide" if outside your own
package.
 
P

P.Hill

Christian said:
In other words, I only want A to be able to instantiate B, and B to
instantiate C

Maybe answering the question about why would you want this, would help
us to understand how to solve your problem.

Inner classes allow the inner class to get at the other one, but
only through normal package access accessors. So you can model
any inner-inner-inner with a gruop of classes in the same package
with various protected and package methods.

For example, if
C requires a B to construct it and A is a factory for B's.

Or there are A, B and C's but the realy working instances
are simplier inner classes which are subclasses of A, B
and C.

-Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top