Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 64 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
64
Dung lượng
428 KB
Nội dung
Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Part VI Abstraction with Interfaces Week 12 HOW TO DESIGN CLASS HIERARCHIES Basic Java Programming Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Comments • • • • Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Comments • ! • " • # • Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Abstracting Over Data Definitions With Object Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Usually, we have seen that data with similar properties. Example : A List of Authors is one of: a empty a structure of an Author a List of Authors An Author contains name dob $# % # $# #% Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) &%'() * ++",! Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) -" .'% ." ! #/ ,!",! Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) ALoObject $,!01 Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) EmptyLoObject 2$,!0 2$,!3401 1 Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) ConsLoObject -$,!0 ,!"5 $,!5 -$,!3,!"$,! 40 "6"5 65 1 1 [...]... material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) • Looking at the definitions of earlier methods that counted the number of objects in the list • Comparing the two contains methods from the problem with stations and routes it is clear that the same code is used to determine whether a list of Routes contains a given Route as the code to determine whether a list of Stations contains a given Station... removes a given object from a list of objects Test your method on the classes of Books, and classes of Shapes Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Abstracting over Data Definitions with Interfaces (Part 1) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Entry ALog Date d double distance int duration String comment + double totalDistance() EmptyLog + double... public double totalValue() { return (this.first.getValue()) + this.rest.totalValue(); } Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Can we replace the list of Books and the list of Entries with a list of Objects? // in the abstract class ALoObject public abstract double totalValue(); // in the class EmptyLoOjbect public double totalValue() { return 0.0; } // in the class ConsLoObjects public... determines whether all objects in this list have a value greater than some threshold specified by the user. Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) ABSTRACTING OVER DATA DEFINITIONS WITH INTERFACES (Part 2) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) • Remind the Sorting examples • Now we compare the method sortByPublicationYear() in the ALoBooks class and the method . (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Part VI Abstraction with Interfaces Week 12 HOW TO DESIGN CLASS HIERARCHIES Basic Java Programming Course material. Definitions With Object Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Course material developed by Mai Anh Tho (tho@hcmuaf.edu.vn) Usually, we have seen that data with similar