注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题

wenhaoyx的个人空间 http://home.eeworld.com.cn/space-uid-362169.html [收藏] [复制] [分享] [RSS]

日志

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

已有 199 次阅读2018-4-22 22:53 | OOP

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.

 

发表评论 评论 (1 个评论)

回复 wenhaoyx 2018-4-22 22:54
感觉这本书英文读起来不那么费劲,没事看看

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

小黑屋|手机版|Archiver|电子工程世界 ( 京ICP证 060456

GMT+8, 2018-5-28 08:59 , Processed in 0.037477 second(s), 11 queries , Gzip On, Redis On.

Powered by EEWORLD电子工程世界

© 2018 http://bbs.eeworld.com.cn/

返回顶部