面向对象设计外文翻译 (2)
《面向对象设计外文翻译 (2)》由会员分享,可在线阅读,更多相关《面向对象设计外文翻译 (2)(10页珍藏版)》请在毕设资料网上搜索。
1、英文原文 Everything is an Object Although it is based on C+, Java is more of a “pure” object-oriented language. Both C+ and Java are hybrid languages, but in Java the designers felt that the hybridization was not as important as it was in C+. A hybrid language allows multiple programming styles; the rea
2、son C+ is hybrid is to support backward compatibility with the C language. Because C+ is a superset of the C language, it includes many of that languages undesirable features, which can make some aspects of C+ overly complicated. The Java language assumes that you want to do only object-oriented pro
3、gramming. This means that before you can begin you must shift your mindset into an object-oriented world (unless its already there). The benefit of this initial effort is the ability to program in a language that is simpler to learn and to use than many other OOP languages. Alown well see the basic
4、components of a Java program and well learn that everything in Java is an object, even a Java program. You manipulate objects with references Each programming language has its own means of manipulating data. Sometimes the programmer must be constantly aware of what type of manipulation is going on.
5、Are you manipulating the object directly, or are you dealing with some kind of indirect representation (a pointer in C or C+) that must be treated with a special syntax? All this is simplified in Java. You treat everything as an object, using a single consistent syntax. Although you treat everything
6、 as an object, the identifier you manipulate is actually a “reference” to an object.10 You might imagine this scene as a television (the object) with your remote control (the reference). As long as youre holding this reference, you have a connection to the television, but when someone says “change t
7、he channel” or “lower the volume,” what youre manipulating is the reference, which in turn modifies the object. If you want to move around the room 1 and still control the television, you take the remote/reference with you, not the television. Also, the remote control can stand on its own, with no t
8、elevision. That is, just because you have a reference doesnt mean theres necessarily an object connected to it. So if you want to hold a word or sentence, you create a String reference: String s; But here youve created only the reference, not an object. If you decided to send a message to s at this
9、point, youll get an error (at run time) because s isnt actually attached to anything (theres no television). A safer practice, then, is always to initialize a reference when you create it: String s = asdf; However, this uses a special Java feature: strings can be initialized with quoted text. Normal
10、ly, you must use a more general type of initialization for objects. You must create all the objects When you create a reference, you want to connect it with a new object. You do so, in general, with the new keyword. The keyword new says, “Make me a new one of these objects.” So in the preceding exam
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中设计图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 面向 对象 设计 外文 翻译
