Hello, i was reading about nested classes and I came accross this example that i found interesting. How valid/accurate/good practice is it? :
"Another possible use of a nested class is when it does not make sense for the class to be a seperate entity, since it serves as a helper to another class. Let's imagine a simplified example of an "Application" class. In order to correctly configure the settings of an application (eg. it's the Dimesions), we may need some information from the user that doesn't have a direct relation with our "Application" class (for example,we may need to know the dimensions of the user's device in order to set up the dimensions for our application). For this reason we use the nested class "ApplicationSettings" that is used as another abstraction layer that provides useful information for our "Application" class :"
It's fine, but it's a pity they called the nested class ApplicationSettings, because the scope that the enclosing Application class provides makes this redundant. What's easier to read: Application.ApplicationSettings, or Application.Settings?
Other examples that I like are when you have an enum that is strongly related to some specific class, then you can nest the enum. For instance a ChessPiece.Color, or a Card.Rank and a Card.Suit. A nice example from the standard API is Map.Entry.
You often see exercises to write a linked list from scratch, or a binary search tree. You would want a Node class, which you would only use internally, so it would make sense to make that a private inner class.
I often see exercises to write a stack, a linked list, or a binary search tree from scratch. Since a node is part of such a data structure, and not used outside, it would make sense to have a private inner Node class. Of course LinkedList.Node, Stack,Node, and BnaryTree.Node would differ from one another.