首页 > 程序开发 > 软件开发 > 其他 >

读《The Object-Oriented Thought Process》书的笔记

2018-05-05

读《The Object-Oriented Thought Process》书的笔记:4 An Anatomy(解剖,分析) of Class。

 4 An Anatomy(解剖,分析) of Class

  /*

  This class defines a cabbie and assigns a cab

  */

  public class Cabbie{

  //Place name of Company Here

  private static String companyName = "Blue Cab Company";

  //Name of the Cabbie

  private String Name;

  //Car assigned to Cabbie

  private Cab myCab;

  //Default Constructor for the Cabbie

  public Cabbie(){

  name = null;

  myCab = null;

  }

  //Name Initializing Constructor for the Cabbie

  public Cabbie(String iName, String serialNumber){

  Name = iName;

  myCab = new Cab(serialNumber);

  }

  //Set the Name of the Cabbie

  public void setName(String iName){

  Name = iName;

  myCab = new Cab(serialNumber);

  }

  //Get the Name of the Company

  public static string getName(){

  return Name;

  }

  }

  //Get the Name of the Cabbie

  public static String getCompanyName(){

  return companyName;

  }

  public void giveDestination(){

  }

  public void turnRight(){

  }

  public void turnLeft(){

  }

  Comments

  星号,斜杠

  */ (asterisk-slash)

  // (slash-slash)

  Attributes

  Static keyword, class attribute..

  The nothingness of null

  Esoteric 深奥的 难解的

  For example, you might want to declare an attribute that will later require user input.

  Thus, you can initialize the attribute to null before the user is actually given the opportunity

  to enter the data.

  Accessors

  Static attributes

  Public interface methods

  The public interface methods tend to be very abstract, and the implementation tends to be more concrete.

  Private implementation methods

  These private methods are simply meant to be part of the implementation and not the public interface.

  Public void giveDestination(){

  .. some code

  turnRight();

  turnLeft();

  .. some code

  }

  encryption methods

  The point here is that private methods are strictly part of the implementation and are not accessible by other classes.

相关文章
最新文章
热点推荐