Thinking in java -6 隐藏的实现 Hidden implementation
2017-06-14 21:47
197 查看
1.从不同角色的角度看类的存在
It is helpful to break up the playing field into class creators (those who create new data types) and client programmers (the class consumers who use the data types in their applications).The goal of the class creator is to build a class that exposes only what’s necessary to the client programmer and keeps everything else hidden. Why? because if it’s hidden, the client programmer can’t access it, which means that the class creator can change the hidden portion at will without worrying about the impact on anyone else. The hidden portion usually represents the tender insides of an object that could easily be corrupted by a careless or uniformed client programmer, so hiding the implementation reduces program bug.
作为类的使用者和类的创建者而言他们所需要的功能是不同的(类的使用者只需将类作为一种新的数据类型使用,并不关心其实现细节;类的创建者则需要精心设计类的具体接口,如类的方法),所需要提供的功能也是不同的。
如此设计有利于数据隐藏,防止类数据遭到破坏,提高代码鲁棒性。
2.实现手段
Java uses three explicit keywords to set the boundaries in a class: public, private and protected.通过使用public/private/protected关键字及默认不加任何修饰手段方法,修饰类的方法和变量来设置访问界限。
相关文章推荐
- Thinking in java笔记之隐藏具体实现
- 【Thinking in java】之实现方案的隐藏
- 【学习笔记】Thinking in java (第三版)第五章 隐藏实现(Hiding the implementation)
- java之旅 (四)隐藏实现 & 复用类
- java线程:单例隐藏ThreadLocal实现线程数据共享
- java单击按钮实现窗口隐藏
- 今天的问题:一个简单的例子,请帮我解开“接口实现Java‘隐藏实现细目’”的迷惑。
- Java中的隐藏实现细节
- 吸血鬼数字的实现(thinking in java练习题)
- Java实现窗体隐藏,功能类似于QQ窗口自动隐藏
- Thinking in Java学习笔记 Thread.UncaughtExceptionHandler接口实现捕获线程内异常
- java编程思想3感悟(4)---被隐藏的具体实现
- 分析JAVA、C#、C++的“覆盖”和“隐藏”与多态的实现
- JAVA基础学习篇----《thinking in java》第五章:隐藏实现
- Java swing开发|Java实现窗体隐藏
- java实现类型QQ,MSN自动停靠隐藏功能
- Java实现任意文件在bmp中的隐藏与导出
- java代码中写得TableLayout,并且实现了空项的自动隐藏
- java隐藏具体实现
- Java实现把窗体隐藏到系统托盘方法