锘??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美视频1区,九色porny丨国产首页在线,国产精品一区二区精品http://www.aygfsteel.com/yuxh/category/42994.htmlwayzh-cnThu, 10 Dec 2009 18:43:40 GMTThu, 10 Dec 2009 18:43:40 GMT60Beginning JO(2 Collection)http://www.aygfsteel.com/yuxh/archive/2009/12/10/305397.htmlyuxhyuxhThu, 10 Dec 2009 03:38:00 GMThttp://www.aygfsteel.com/yuxh/archive/2009/12/10/305397.htmlhttp://www.aygfsteel.com/yuxh/comments/305397.htmlhttp://www.aygfsteel.com/yuxh/archive/2009/12/10/305397.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/305397.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/305397.html
閫氬父鏈変袱縐嶆柟娉曞彲浠ユ墿灞昪ollection 鏉ユ弧瓚充竴浜涢渶瑕侊細(xì)緇ф壙鏌愮闆嗗悎綾誨瀷鍜屽皝瑁呮煇縐嶉泦鍚堢被鍨嬨傜涓縐嶇殑浼樼偣鏄垵濮嬪寲鐨勬椂鍊欏湪鍐呭瓨涓彧浜х敓涓涓璞★紝榪欐槸緇ф壙鐗規(guī)у喅瀹氱殑銆傚悗鑰呯殑浼樼偣鏄垜浠彲浠ユ柟渚挎帶鍒惰灝佽闆嗗悎鐨勫悇縐嶅睘鎬с?br />
Whenever possible, it’s desirable to bury implementation details inside of a class rather than exposing client code to such details銆備緥錛?br />
娉?錛?br />
public class Student {
private String name;
private String studentId;
private ArrayList<TranscriptEntry> transcript; //鎴愮嘩鎶ュ憡鍗?br />
public void addTranscriptEntry(TranscriptEntry te) { // 鎿嶄綔transcript杈懼埌璁板綍鎴愮嘩
// Store the TranscriptEntry in our ArrayList.
transcript.add(te);
}
}
瀹㈡埛绔皟鐢ㄤ唬鐮侊細(xì)
Student s = new Student("1234567", "James Huddleston");
Course c = new Course("LANG 800", "Advanced Language Studies");
TranscriptEntry te = new TranscriptEntry(c, "Fall 2006", "B+");
s.addTranscriptEntry(te);
娉?錛?br />
寤虹珛鏂板璞★紝灝佽涓涓狝rrayList錛?br />
public class Transcript {
private ArrayList<TranscriptEntry> transcriptEntries;
public void courseCompleted(Course c, String semester, String grade) {
// Instantiate and insert a brand-new TranscriptEntry object into the
// ArrayList - details hidden away!
transcriptEntries.add(new TranscriptEntry(c, semester, grade);
}
}
public class Student {
private String name;
private String studentId;
// This used to be declared as an ArrayList.
private Transcript transcript;
// etc.
}
瀹㈡埛绔唬鐮侊細(xì)
s.courseCompleted(c, "Spring 2006", "A+");
絎簩縐嶆柟娉曚嬌Student澶勭悊鏇村皯鐨勭粏鑺傦紝涓嶇敤綆ranscripts鎬庝箞琛ㄨ揪錛岀湅涓嶅埌TranscriptEntry鐨勫瓨鍦ㄣ傚鎴風(fēng)浠g爜鏇寸畝鍗曘?
]]>Beginning Java Objectshttp://www.aygfsteel.com/yuxh/archive/2009/12/08/305181.htmlyuxhyuxhTue, 08 Dec 2009 08:57:00 GMThttp://www.aygfsteel.com/yuxh/archive/2009/12/08/305181.htmlhttp://www.aygfsteel.com/yuxh/comments/305181.htmlhttp://www.aygfsteel.com/yuxh/archive/2009/12/08/305181.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/305181.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/305181.htmlAggregation is a special form of association, alternatively referred to as the “consists of”, “is composed of”, or “has a” relationship.Like an association, an aggregation is used to represent a relationship between two classes, A and B. But, with an aggregation, we’re representing more than mere relationship: we’re stating that an object belonging to class A, known as an aggregate,is composed of, or contains, component objects belonging to class B.
Note that these aggregation statements appear very similar to associations, where the name of the association just so happens to be is composed of or contains. That’s because an aggregation is an association in the broad sense of the term錛坅ggregation 鏄痑ssociation鐨勪竴縐嶇壒孌婅〃鐜板艦寮忥級(jí)!aggregation 鍜宎ssociations UML琛ㄧ幇涓嶅悓浣嗘渶緇堜唬鐮佽〃鐜板艦寮忎竴鏍?br />
Composition is a strong form of aggregation, in which the “parts” cannot exist without the “whole.” As an example, given the relationship “a Book is composed of many Chapters”, we could argue that a chapter cannot exist if the book to which it belongs ceases to exist; whereas given the relationship “a Car is composed of many Wheels”, we know that a wheel can be removed from a car and still serve a useful purpose. Thus, we’d categorize the Book–Chapter relationship as composition and the Car–Wheel relationship as aggregation.
緇ф壙娌$暀鎰忕殑濂藉錛?br />
• Best of all, we can derive a new class from an existing class even if we don’t own the source code for the latter! As long as we have the compiled bytecode version of a class, the inheritance mechanism works just fine; we don’t need the original source code of a class in order to extend it. This is one of the most dramatic ways to achieve productivity with an objectoriented language: find a class (either one written by someone else or one that is built into the language) that does much of what you need, and create a subclass of that class,adding just those features that you need for your own purposes.
• classification is the natural way that humans organize information; so, it only makes sense that we’d organize software along the same lines, making it much more intuitive and hence easier to develop, maintain,extend, and communicate with users about.
緇ф壙涓嶢ssociation, aggregation寮傚悓錛圥186錛夛細(xì)
Association, aggregation, and inheritance are all said to be relationships between classes. Where inheritance differs from association and aggregation is at the object level.inheritance is indeed a relationship between classes, but not between distinct objects. 娉ㄦ剰錛氶伩鍏嶈繛閿佸弽搴旓紝Whenever possible, avoid adding features to non-leaf classes once they have been established in code form in an application, to avoid ripple effects throughout an inheritance hierarchy. 璇存瘮鍋氬鏄擄紝榪欏氨瑕佹眰鍦ㄧ紪鐮佷箣鍓嶅敖鍙鐨勮姳鏃墮棿鍦ㄩ渶姹傚垎鏋愬拰瀵硅薄寤烘ā闃舵錛岃櫧鐒朵笉鑳介伩鍏嶆柊闇姹傚嚭鐜幫紝浣嗚嚦灝戦伩鍏嶅拷瑙嗛仐婕忎簡(jiǎn)褰撳墠鐨勯渶姹傘?
Overriding:瀛愮被緇ф壙鐖剁被錛岄噸鍐欏敮涓鑳芥敼鍙樼殑鏄柟娉曠殑璁塊棶鎺у埗錛岃屼笖鍙兘姣旂埗綾繪洿瀹芥澗錛屽鐖剁被鐢ㄧ殑鏄痯rivate錛屽瓙綾誨彲浠ョ敤public銆傚弬鑰冧簡(jiǎn)涓媡hinking in java 4th P202 鍙戠幇榪欑璇存硶涓嶅錛岃屼笖鏄竴涓?span style="color: red">闄烽槺錛氱埗綾葷殑璇ユ柟娉曟牴鏈瀛愮被涓嶅彲瑙侊紒瀛愮被鐨勮鏂規(guī)硶瀹為檯涓婃槸涓涓叏鏂扮殑鏂規(guī)硶錛岃繛閲嶈澆閮界畻涓嶄笂銆傛墍浠ュ彧鑳介噸鍐檔on-private鏂規(guī)硶銆傞亣鍒皃rivate鏂規(guī)硶浣犲緱灝忓績(jī)錛屾病鏈夌紪璇戦敊璇紝浣嗕笉浼?xì)鍍忎綘鎯宠薄鐨勫伐浣滃Q屾渶濂界粰鏂規(guī)硶閲嶆柊鍙栧悕錛岄伩鍏嶉櫡闃便?br />
涓嶈鍋氱殑浜嬫儏錛?br />
We shouldn’t change the semantics鈥攖hat is, the intention, or meaning鈥攐f a feature.For example:
• If the print method of a superclass such as Student is intended to display the values of all of an object’s attributes in the command window, then the print method of a subclass such as GraduateStudent shouldn’t, for example, be overridden so that it directs all of its output to a file instead.
• If the name attribute of a superclass such as Person is intended to store a person’s name in “last name, first name” order, then the name attribute of a subclass such as Student should be used in the same fashion.
We can’t physically eliminate features, nor should we effectively eliminate them by ignoring them. To attempt to do so would break the spirit of the “is a” hierarchy. By definition, inheritance requires that all features of all ancestors of a class A must also apply to class A itself in order for A to truly be a proper subclass. If a GraduateStudent could eliminate the degreeSought attribute that it inherits from Student, for example, is a GraduateStudent really a Student after all? Strictly speaking, the answer is no.
榪涗竴姝ヤ粠瀹炵敤瑙掑害璇達(dá)紝濡傛灉鎴戜滑閲嶅啓涓涓柟娉曚絾涓嶅湪榪欐柟娉曢噷鍋氫換浣曚簨鎯咃紝鍏朵粬緇ф壙鎴戜滑綾葷殑浜哄氨浼?xì)鍑洪棶棰樺Q氫粬浠寰楁垜浠殑鏂規(guī)硶鏄湁鎰忎箟鐨勶紙鐗瑰埆鏄粬浠笉鑳界湅鍒版垜浠簮浠g爜鐨勬椂鍊欙級(jí)銆傝屾垜浠垯鎵撶牬浜?#8220;is a” 鍘熷垯錛屾墍浠ョ粷涓嶈榪欐牱鍋氾紒
protected鍏抽敭瀛楃殑榪愮敤錛岀敤浜庢帶鍒剁戶鎵跨殑璁塊棶鎺у埗銆?br />
榪愮敤super(arguments) 鍑忓皯瀛愮被鏋勯犲嚱鏁伴噸澶嶇埗綾繪瀯閫犲嚱鏁頒唬鐮侊紝鍜宼his綾諱技蹇呴』鍦ㄦ瀯閫犲嚱鏁版渶寮濮嬭皟鐢ㄣ?br />
Student s = new Student("Fred", "123-45-6789"); 鎵ц榪欐浠g爜錛孫bject鐨勬瀯閫犲嚱鏁頒細(xì)鑷姩鎵ц錛屾帴鐫Student 鐨勭埗綾籔erson鏋勯犲嚱鏁頒粩緇嗭紝鐒跺悗鏄垜浠皟鐢ㄧ殑Student鏋勯犲嚱鏁幫紝濡傛灉璋冪敤鐨凷tudent鏋勯犲嚱鏁版病鏈夋樉紺鴻皟鐢ㄧ埗綾繪瀯閫犲嚱鏁幫紝鍒欑浉褰撲簬榛樿璋冪敤super() 銆?br />
java娌℃湁綾葷殑澶氱戶鎵匡紝澶氱戶鎵垮緢澶嶆潅鐨勪竴鐐癸紝濡傛灉涓や釜鐖剁被閮芥湁鐩稿悓鐨勬柟娉曪紝瀛愮被鎬庝箞澶勭悊錛?