W9_Live-Object-Oriented Programming and Design Principles
(1) Page 11
(2) Page 31-36
两个 code 例子对比,没看懂如何体现了More Generic的思想
两个code例子转译在下面两个代码块了,缩进之类的重排之后应该没有破坏原意。。。应该没有。。。
(在PPT直接贴代码的英方是屑)
public class Card { // Class to represent playing cards.private int suit; // Number from 0 to 3 that codes for the suit --// spades, diamonds, clubs or hearts.private int value; // Number from 1 to 13 that represents the value.public boolean equals(Object obj) {try {Card other = (Card)obj; // Type-cast obj to a Card.if (suit == other.suit && value == other.value) {// The other card has the same suit and value asreturn true;}else return false;}catch (Exception e) {// This will catch the NullPointerException that occurs if obj// is null and the ClassCastException that occurs if obj is// not of type Card. In these cases, obj is not equal to// this Card, so return false.return false;}}// other methods and constructors}
/*** Represents a full name consisting of a first name and a last name.*/public class FullName implements Comparable<FullName> {private String firstName, lastName; // Non-null first and last names.public FullName(String first, String last) { // Constructor.if (first == null || last == null)throw new IllegalArgumentException("Names must be non-null.");firstName = first;lastName = last;}public boolean equals(Object obj) {try {FullName other = (FullName)obj; // Type-cast obj to typeFullNamereturn firstName.equals(other.firstName) && lastName.equals(other.lastName);}catch (Exception e) {return false; // if obj is null or is not of type FullName}}public int compareTo( FullName other ) {if ( lastName.compareTo(other.lastName) < 0 ) {// If lastName comes before the last name of// the other object, then this FullName comes// before the other FullName. Return a negative// value to indicate this.return -1;}else if ( lastName.compareTo(other.lastName) > 0 ) {// If lastName comes after the last name of// the other object, then this FullName comes// after the other FullName. Return a positive// value to indicate this.return 1;}else {// Last names are the same, so base the comparison on// the first names, using compareTo from class String.return firstName.compareTo(other.firstName);}}// other methods and constructors}
W9_Rec-Design_Principles-1
(1) Page 63
W10_Live_Designing_Programs_Networking_and_Defensive_Programming
(1) Page 7
(2) Page 13
W11_Rec_Design_Patterns
(1) Page 37-41
工厂方法懂了,但没完全懂
