Summary of Chapter 10 of the fourth edition of Java programming ideas
1. Characteristics of internal classes
2. Use this
3. Use new
4. Inner class of method
5. Define the internal class within the scope, which is within the method
6. Anonymous inner class
7. Talk about factory design mode again
In the last chapter, we talked about the factory design pattern The case in this book is the object factory design pattern Let's see how it's written
We can also implement this method as an inner class
My understanding is: the first factory means that I need a service now, and then I find the corresponding factory to provide services for me The factory then looks for the entity corresponding to this service
And the second way, I need service now Just go to the factory corresponding to this service That is, it is built in the factory Just as a large company has many subsidiaries, each subsidiary has its own factory I want that type of thing, so he produces it himself
8. Nested classes
If the inner class object does not expect a connection between the outer class objects, the inner class can be declared static. This is often referred to as a nested class. To understand the meaning of the internal class defined by static, you must remember that an ordinary internal class object implicitly holds a reference to the peripheral class object that created it. However, this is not the case when the inner class is static. Nested classes mean:
9. Classes inside the interface
10. Access members of external classes from multi-level nested classes
Notice how the following example creates an inner class.
iooo