Java Nested class
本人在看Android文档的时候发现有个Java语法还挺有意思的,就是Java Nested class,查看了sun的文档,原来是类里面的嵌套类。http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html
本人介绍一篇文章给大家看看:http://www.cn-java.com/www1/bbs/redirect.php?tid=13595&goto=lastpost&sid=D7zYoM
为什么要使用 Nested class???官方的解释如下
1、类在逻辑山的分组
2、增加封装性
3、代码可以更好地维护
Why Use Nested Classes?
There are several compelling reasons for using nested classes, among them:
- It is a way of logically grouping classes that are only used in one place.
- It increases encapsulation.
- Nested classes can lead to more readable and maintainable code.
Logical grouping of classes —If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together. Nesting such "helper classes" makes their package more streamlined.
Increased encapsulation —Consider two top-level classes, A and B, where B needs access to members of A that would otherwise be declared private
. By hiding class B within class A, A's members can be declared private and B can access them. In addition, B itself can be hidden from the outside world.
More readable, maintainable code —Nesting small classes within top-level classes places the code closer to where it is used.
更多相关文章
- 安卓ScrollView嵌套RecyclerView,GridView,ViewPager冲突解决
- android 官方文档阅读记录-多屏幕适配
- Android(安卓)Web App官方文档翻译第三章:WebView构建应用
- 关于使用腾讯云腾讯(即时通讯SDK)遇到的问题
- Android(安卓)NestedScrolling嵌套滑动机制
- 20170524Android笔记
- ScrollView嵌套ViewPager,ViewPager内容不显示问题
- Android(安卓)UI设计 ViewPager 中嵌套HorizontalScrollView
- android 6.0(api 23) SDK,不再提供org.apache.http.*(只保留几个