W9_Live-Object-Oriented Programming and Design Principles

(1) Page 11

如何理解这两句话
image.png

(2) Page 31-36

两个 code 例子对比,没看懂如何体现了More Generic的思想
两个code例子转译在下面两个代码块了,缩进之类的重排之后应该没有破坏原意。。。应该没有。。。
(在PPT直接贴代码的英方是屑)

  1. public class Card { // Class to represent playing cards.
  2. private int suit; // Number from 0 to 3 that codes for the suit --
  3. // spades, diamonds, clubs or hearts.
  4. private int value; // Number from 1 to 13 that represents the value.
  5. public boolean equals(Object obj) {
  6. try {
  7. Card other = (Card)obj; // Type-cast obj to a Card.
  8. if (suit == other.suit && value == other.value) {
  9. // The other card has the same suit and value as
  10. return true;
  11. }
  12. else return false;
  13. }
  14. catch (Exception e) {
  15. // This will catch the NullPointerException that occurs if obj
  16. // is null and the ClassCastException that occurs if obj is
  17. // not of type Card. In these cases, obj is not equal to
  18. // this Card, so return false.
  19. return false;
  20. }
  21. }
  22. // other methods and constructors
  23. }
  1. /**
  2. * Represents a full name consisting of a first name and a last name.
  3. */
  4. public class FullName implements Comparable<FullName> {
  5. private String firstName, lastName; // Non-null first and last names.
  6. public FullName(String first, String last) { // Constructor.
  7. if (first == null || last == null)
  8. throw new IllegalArgumentException("Names must be non-null.");
  9. firstName = first;
  10. lastName = last;
  11. }
  12. public boolean equals(Object obj) {
  13. try {
  14. FullName other = (FullName)obj; // Type-cast obj to type
  15. FullName
  16. return firstName.equals(other.firstName) && lastName.equals(other.lastName);
  17. }
  18. catch (Exception e) {
  19. return false; // if obj is null or is not of type FullName
  20. }
  21. }
  22. public int compareTo( FullName other ) {
  23. if ( lastName.compareTo(other.lastName) < 0 ) {
  24. // If lastName comes before the last name of
  25. // the other object, then this FullName comes
  26. // before the other FullName. Return a negative
  27. // value to indicate this.
  28. return -1;
  29. }
  30. else if ( lastName.compareTo(other.lastName) > 0 ) {
  31. // If lastName comes after the last name of
  32. // the other object, then this FullName comes
  33. // after the other FullName. Return a positive
  34. // value to indicate this.
  35. return 1
  36. }
  37. else {
  38. // Last names are the same, so base the comparison on
  39. // the first names, using compareTo from class String.
  40. return firstName.compareTo(other.firstName);
  41. }
  42. }
  43. // other methods and constructors
  44. }

W9_Rec-Design_Principles-1

(1) Page 63

这一页的内容没看懂
image.png

W10_Live_Designing_Programs_Networking_and_Defensive_Programming

(1) Page 7

这一页都不是特别懂,尤其是最后一个点
image.png

(2) Page 13

红框的这点没太懂
image.png

W11_Rec_Design_Patterns

(1) Page 37-41

工厂方法懂了,但没完全懂