Topic: 关于类的保护 |
Print this page |
1.关于类的保护 | Copy to clipboard |
Posted by: HJILY44 Posted on: 2004-11-02 15:30 请问有没有保护一个类的必要,什么时候需要保护一个类???? |
2.Re:关于类的保护 [Re: HJILY44] | Copy to clipboard |
Posted by: littledeer1974 Posted on: 2004-11-02 15:33 你所说的保护,是指什么呢? 是不是说,能不能用protected来修饰?还是另有含义呢? |
3.Re:关于类的保护 [Re: HJILY44] | Copy to clipboard |
Posted by: HJILY44 Posted on: 2004-11-02 15:38 protected class a这样修饰的话这个类还有作用吗?什么时候需要这样修饰? |
4.Re:关于类的保护 [Re: HJILY44] | Copy to clipboard |
Posted by: littledeer1974 Posted on: 2004-11-02 15:53 1.首先,回答是有 这里就能看到一个 2.关于必要性,和时机 我想得先对几个修饰符有一个大致的认识 这里有一点讨论 还有这里 明白了protected这个关键字的意义,那它来修饰class也有相同的作用 ---------------------------from Thinking in Java----------------------------- -------------------------------By Bruce Eckel--------------------------------- protected Now that you’ve been introduced to inheritance, 现在,你已经学习了继承 the keyword protected finally has meaning. protected的含义也应该变得清晰了吧 In an ideal world, the private keyword would be enough. 在理想状态下仅有 private就够了 In real projects, there are times when you want to make something hidden from the world at large and yet allow access for members of derived classes. 但是在实际的开发中,你肯定会有这样的想法,那就是,大多数的人都看不到你定义的成员,而只有继承它的成员才能看得到它 The protected keyword is a nod to pragmatism. protected就是你想要的(就能帮你实现这个想法) It says “This is private as far as the class user is concerned, but available to anyone who inherits from this class or anyone else in the same package.”它会这样对你说[别人用的时候它就是private ,但你要是继承它的话或是和它在同一个package里呢,就可以随便用了] (In Java, protected also provides package access.)JAVA中protected也准许包内的访问 The best approach is to leave the fields private; 最简单的就是让所有的域都设置成private you should always preserve your right to change the underlying implementation. You can then allow controlled access to inheritors of your class through protected methods: //: c06:Orc.java You can see that change( ) has access to set( ) because it’s protected. Also note the way that Orc’s toString( ) method is defined in terms of the base-class version of toString( ). Feedback ---------------------------from Thinking in Java----------------------------- -------------------------------By Bruce Eckel--------------------------------- |
5.Re:关于类的保护 [Re: HJILY44] | Copy to clipboard |
Posted by: chengbd Posted on: 2004-11-02 18:02 问问题真不如自己动手先找找,请看这个帖子: http://www.cjsdn.net/post/view?bid=1&id=119395&sty=3&keywords=private%2Cprotected%2C+public 我复制了一些内容: 1、作用域public,private,protected,以及不写时的区别 答:区别如下: 作用域 当前类 同一package 子孙类 其他package public √ √ √ √ protected √ √ √ × friendly √ √ × × private √ × × × 不写时默认为friendly 学东西应该放主动了,先主动故助别人,再想得到别人的帮助,真希望大家也经常来参与交流,不要只关心自己的问题,一点感想,和问题无关。 |
6.Re:关于类的保护 [Re: HJILY44] | Copy to clipboard |
Posted by: chengbd Posted on: 2004-11-02 18:09 “保护一个类”,应该是说防止“反编译”了,可以通过obfuscator工具(混淆器)来实现。 |
7.Re:关于类的保护 [Re: HJILY44] | Copy to clipboard |
Posted by: AnthonyPig Posted on: 2004-11-06 23:32 访问修饰符 打包成JAR(带有安全标识的) 加密 序列化 不犯常识性错误 …… |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |