模块之间通过他们的api通信,一个模块不需要知道另外一个模块的内部情况,这就被称为信息隐藏或封装。
请问为什么需要封装?
答:需要封装的原因很多,其中大多数的原因都源于这么一个事实:你可以有效的解除组成系统个模块之间的耦合关系,使这些模块可以独立开发,测试,优化,修改,理解,这样可以加快系统开发的速度,因为这些模块可以并行开发。它也减轻了维护的负担,因为我们可以更快点的理解这些模块,并在调用的时候不影响其他模块。
封装提高了软件的可重用性,因为模块之间不紧密相连,最后封装也降低了构建大型系统的风险,即使整个系统不可用,但是这些模块可能是有用的。
使类和成员的可访问性最小化
对于顶层的类或接口,只有两种可能访问的级别:包级私有的(package private)和公有的(public),如果你使用了public修饰顶层类或接口,那它就是公有的;否则它就是包级私有的,通过把类或接口设计成包级私有的,它实际上成了这个包实现的一部分,在以后的版本重,可以对它进行修改,替换,或者删除,而无需担心会影响到现有客户端程序。如果你把它设计成public,你就有责任永远支持它,以保持他们的兼容性。
对于成员(域、方法、嵌套类和接口)有四种可能的访问级别,下面按照可访问性的递增顺序罗列出来:
私有的:只有在声明该成员的顶层类的内部才可以访问这个成员。
包级私有的:声明该成员的包内部的任何类都可以访问这个成员。它被成为缺省(default)访问级别。
受保护的(protected):声明该成员的类的子类可以风味这个成员变量,并且声明 该成员的包的内部的任何类也可以访问这个成员。
公有的(public)任何地发都可以访问该成员。
注意:长度非零的数组总是可变的,所以,类具有公有的静态final数组域。或者返回这种域的访问方法,这几乎总是错误的。如果类具有这样域或者访问方法,客户端将能够修改数组中的内容。这是安全漏洞的一个常见根源:
public static final Thing[] values={.......};
修改这个问题有两种方法。可以使用公有的数组变成私有的,并且增加一个公有的不可变列表
class ArraysAcess {
private static final String[] PRIVATE_VALUES ={"a","b","c","d"};
public static final List<String> values = Collections.unmodifiableList(Arrays.asList(PRIVATE_VALUES));
}
//测试:
public static void main(String[] args) {
// TODO Auto-generated method stub
java.util.List<String> list = ArraysAcess.values;
list.add("abc");
for(int i=0;i<list.size();i++){
System.out.println("value:"+list.get(i));
}
}
就会报错如下:
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.add(Collections.java:1018)
at classandmemberacess.tets.main(tets.java:13)
因为这时候的数组变成了大小固定,不可修改的集合了。
另外一种修改方法是:
class ArraysAcess {
private static final String[] PRIVATE_VALUES = {"a","b","c","d"};
//second method
public static final String[] getValues(){
return PRIVATE_VALUES.clone();
}
}
分享到:
相关推荐
In this paper a information hiding algorithm applied to compressed speech bitstream is proposed. Covering codes are used to hide information in the least important bits in G.729 frames. The embedding ...
An approach of speech inform ation hiding based on G.729 scheme,and ABS(Analysis—by—synthesis) algorithm of speech inform ation hiding and extracting, which form ing the theoretical basis for ...
09 信息隐藏会关于隐写和隐写分析的论文
information hiding dct matlab
Lossless Information Hiding in Images 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请...
Abstract-Traditional speech information hiding methods have several disadvantages, for example, constant embedding amplitude, lower speech quality, higher bit error rate. A novel speech information ...
information hiding. To shorten the time of building link and exchanging protocol, this paper presents a technology for fast cross-identification. To enhance the security of communication, encryption ...
paper, DCT is used for speech information hiding. Secret information is embedded by changing the parameters in DCT domain and extracted by statistical method at the receiving end. Results of analysis ...
设置隐试打开PPT报错 Hiding the application window is not allowed
The extraction of binary information hiding algorithm based on image segmentation
Abstract—In this paper, a new idea for speech information hiding using fractional cosine transform (FRCT) is proposed. We find in our analysis that the 3rd parameter of FRCT presents property of high...
信息隐藏技术初探 作者:杨溯 来源:《信息安全与技术》2015年第07期 【 摘 要 】 论文提出了一种信息隐藏技术,首先采用DES加密算法将文件进行加密,然后通过信息隐 藏,将加密文件隐藏到BMP图片中,载密图片与原始...
1. Encapsulation/Information Hiding (封装/信息隐藏) 2. Inheritance (继承) 3. Polymorphis
用matlab编写的在png图像中隐藏并提取rgb图像和二值图像,注意隐藏的图像要小点,源图像png要大些
无失真数据压缩技术的信息隐藏论文 Information Hiding on Lossless Data Compression
根据An Improved Reversible Data Hiding in Encrypted Images Using Side Match 这篇文章编写的matlab 程序 文件夹里面有文章和代码
信息隐藏技术综述 信息隐藏简介 信息隐藏(Information Hiding),也称作数据隐藏(Data Hiding),或称作数字水印(Digital Watermarking)。简单来讲,信息隐藏是指将某一信号(一般称之为签字信号,Signat ure ...
采用MATLAB实现图像信息隐藏。将文本信息,通过DCT和LSB算法嵌入到二维图像中实现信息隐藏。
Xinpeng, “Information hiding in text using typesetting tools with stego-encoding,” in ICICIC ’06: Proceedings of the First International Conference on Innovative Computing, Information and Control...