|
Whenever you need some functionality in a class, the idea of declaring a class within another class may look like going against object-oriented approach. You may also feel that it is better to declare a top-level class implementing that functionality and then use that class. Such class would be usable by other classes as well. What possible advantage can you get by declaring a class within class to implement the desired behavior? Let us discuss certain situations where declaring a class-within-a-class offers better solution than the top-level class.