Note of 《thinking in java》5
2008-02-05 13:19
232 查看
5. Hiding the Implementation[/u]
A primary consideration in object-oriented design is "separating the things that change from the things that stay the same."
There can be only one public class in each compilation unit, otherwise the compiler will complain.
A working program is a bunch of .class files, which can be packaged and compressed into a Java ARchive(JAR) file(using Java's jar archiver).
The Java interpreter finds the environment variable CLASSPATH(set via the operating system, and sometimes by the installation program that installs Java or a Java-based tool on your machine).
The CLASSPATH can contain a number of alternative search paths.
When the compiler encounter the import statement for the current library, it begins searching at the directories specified by CLASSPATH.
All objects can easily be force into String representation by putting them in a String expression.
Don't make the mistake of thinking that Java will always look at the current directory as one of the starting points for searching. If you don't have a '.' as one of the paths in your CLASSPATH, Java won't look there.
You might not initially think you'll use the private keyword often since it's tolerate to get away without it. (This is a distinct contrast with C++.)
A reference to an object is private inside a class doesn't mean that some other object can't have a public reference to the same object.
Since the default constructor is the only one defined, and it's private, it will prevent inheritance of this class.
Sometimes the creator of the base class would like to take a particular member and grant access to derived classes but not the world in general. That's what protected does.
Classes browsers have become an expected part of any good Java development tool.
Note that a class can not be private(that would make it accessable to no one but the class) or protected.
If you don't want anyone else to have access to that class, you can make all the constructors private, thereby preventing anyone but you, inside a static member of the class, from creating an object of that class.
Actually, an inner class can be private or protected, but that's a special case.
A primary consideration in object-oriented design is "separating the things that change from the things that stay the same."
There can be only one public class in each compilation unit, otherwise the compiler will complain.
A working program is a bunch of .class files, which can be packaged and compressed into a Java ARchive(JAR) file(using Java's jar archiver).
The Java interpreter finds the environment variable CLASSPATH(set via the operating system, and sometimes by the installation program that installs Java or a Java-based tool on your machine).
The CLASSPATH can contain a number of alternative search paths.
When the compiler encounter the import statement for the current library, it begins searching at the directories specified by CLASSPATH.
All objects can easily be force into String representation by putting them in a String expression.
Don't make the mistake of thinking that Java will always look at the current directory as one of the starting points for searching. If you don't have a '.' as one of the paths in your CLASSPATH, Java won't look there.
You might not initially think you'll use the private keyword often since it's tolerate to get away without it. (This is a distinct contrast with C++.)
A reference to an object is private inside a class doesn't mean that some other object can't have a public reference to the same object.
Since the default constructor is the only one defined, and it's private, it will prevent inheritance of this class.
Sometimes the creator of the base class would like to take a particular member and grant access to derived classes but not the world in general. That's what protected does.
Classes browsers have become an expected part of any good Java development tool.
Note that a class can not be private(that would make it accessable to no one but the class) or protected.
If you don't want anyone else to have access to that class, you can make all the constructors private, thereby preventing anyone but you, inside a static member of the class, from creating an object of that class.
Actually, an inner class can be private or protected, but that's a special case.
相关文章推荐
- Note of 《thinking in java》1
- Note of 《thinking in java》2
- Note of 《thinking in java》4
- Note of 《thinking in java》6
- Note of 《thinking in java》3
- Reading "Thinking in Java" #4
- Reading "Thinking in Java" #5
- 《Thinking in Java》并发练习题
- thinking in java
- JAVA基础学习篇----《thinking in java》第六章:代码复用
- Reading "Thinking in Java" #6
- 读第一遍Thinking in java的笔记
- 很多人知道《Thinking in Java》吧,那么《Thinking in C#》呢?
- 《Thinking in Java》——静态、非静态成员变量、子句的初始化顺序(含继承)及对象创建过程
- thinking in java test3.11练习(11)(12)(13)
- [Thinking_in_Java] 初始化与清理 —— initialize
- Thinking in Java之Set接口、HashSet源码学习
- Thinking in java学习笔记之持有对象总结
- 《Thinkinginjava》第10章-内部类
- Thinking in Java from Chapter 21