What is a nested class?

In object -oriented programming (OOP) is a nested class class, which is completely contained in another class. For this object -oriented structure, it has support of a number of computer languages, including the C ++ and Java programming language. If the nested class is not declared static, it can also be called the inner class. The class may contain any number of inner classes and each internal class can also contain its own internal classes. Nested classes can be very useful, but can also quickly complicate class structures, so it is best to use them as part of a careful plan to avoid unnecessarily complex. For example, if class A contains a group of methods that only uses these methods can be grouped into internal class B. Methods inside the inner class have access to variables and external class methods, while maintaining their own variables or constants as needed. The nested class can be used as a functional or organizational construct; Although it is useful to encapsulate functionality,It is as useful as an organizational tool. The ideal use of internal classes will be grouped with related functions and organize code for easier readability and understanding.

Commenting should be made on a nested class as well as in the outer class; For beginners, it is easy to confuse internal classes with methods and forget it. When commenting on a nested class, it is best to be considered a highest level and comment accordingly. The internal class comments also provide the programmer with the opportunity to clarify the functionality of the internal class and justify its organizational scheme. There may be multiple inner classes within a single outer class, so it's particularly important for progrummer to clearly comment on each of them.

If the nested class is not declared static, the instance of the outer class must be explicitly created before creating an internal class instance. In the inner classes thatThey are declared static, this is not true. A static nested class can usually be created with a smaller number of keys and can have a wider range than a simple inner class, so static nested classes are useful for creating easily accessible usefulness, such as factories or simple separate applications.

is often useful for developers when the nested classes are described using the language of unified modeling. The unified modeling language of the annotation and illustrates the structure and behavior of the class clearly, often using diagrams. The nested classes receive independent descriptions from the outer classes in which they live, so it is very easy to identify and analyze their functionality. Although this is not required for a nested Be Annotated class in this way, it is often better for programmers to be wrong on the side of greater detail.

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?