《The Object-Oriented Thought Process》讀書筆記1

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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章