数据结构、算法与应用-C++描述1.ppt
文本预览下载声明
* * * * * * The two most important concepts in object-oriented programming are the class and the object. In the broadest term, an object is a thing, both tangible and intangible, which we can imagine. A program written in object-oriented style will consist of interacting objects. For a program to maintain bank accounts for a bank, we may have many Account, Customer, Transaction, and ATM objects. An object is comprised of data and operations that manipulate these data. * * * This diagram shows three instances of the Employee class. Their names are Bill, Steve, and Andy. They are more commonly referred to as Employee objects. One key fact to remember: A class must be defined before you can create an instance (object) of the class. * Notice that the name of the message we send to an object or a class must be the same as the method’s name. Because they are the same, the message name is commonly omitted from the diagram as shown above. Because they are the same, the phrase “calling an object’s method” is synonymous to “sending a message to an object.” * The deposit method in the previous slide is an action-only method. It takes some action when called, but returns no answer back to the caller. The getMonthlyFee method above is a value-returning method. When called, it returns a value. A method can be both: executes an action and returns some value. * * 类的图形表示 Account 类的名字 方角矩形是一个类的图标 * * 实例的关系 Employee Employee Bill Employee Steve Employee Andy 这是为一个类创建了三个对象,在对象的图标中类的名字可省略。 虚线表示实例的关系。 在建立实例之前,类必需已经有定义。 * * 消息和方法 要让类的实例或对象完成一项任务,我们必需给它发送一个消息(message)。 消息只能发送给能够理解这个消息的类或对象。 所接受的消息,类或对象必需具有处理该消息的方法(method)。 传递给对象的数据称为消息变量(argument)。 发送new消息建立一个类的示例 * * 发送消息 给对象chk-008发送带有变量250.00的deposit消息 Account chk-008 deposit deposit 250.00 在图形中消息的名可以省略 deposit 250.00 * * 发送消息得到返回值 这个消息没有变量 Account chk-008 getMonthlyFee monthly fee monthly fee返回给消息发送者 * * class Currency { public: // 构造函数 Currency(sign s=plus,unsigned long d=0, unsigned int c=0); // 析构函数
显示全部