UML_Lec01_2_面向对象基础.pptVIP

  1. 1、本文档共33页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  5. 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  6. 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  7. 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  8. 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
UML_Lec01_2_面向对象基础

练习 例如,假定要求你对家庭用水系统建模。那么有哪些对象可用于表示供水系统的各种部件呢? Faucet object(水龙头) 方法:打开水流/关闭水流,设定流速,返回给定时间段的用水量等等。 为了完成这项任务,水龙头对象需要实例变量来记录水龙头开、关、用了多少水、水从哪里来等信息。 供水模型中可能还有水管对象,负责运水; 有节水阀对象,调节水管中的水流速度。 一些应用对象—如洗碗机、盥洗室和洗衣机。 当建筑物被要求报告用了多少水时 可能还有一个建筑物 对象, 容纳一些水管、阀、水龙头 它可以要求每个水龙头、阀报告自己的当前状态 整个系统是一个又一个对象网络 对象相互调用来解决问题。每个对象都有专门的角色,完成部分工作,有能力和其他的对象交互。 对象间通过消息(message) 来执行交互,请求执行某一个方法 。 * Basic Terminology 1: Inheritance Inheritance is a way of relating two classes so that one class may use another classs members without redefining them. The basic principle is simple: A class gets the state and behaviour of another class and adds additional state and behaviour. * How do you express inheritance in C++? ?class?Car?:?public?Vehicle?{ ?public: ???... ?}; * We state the above relationship in several ways: Car is a kind of a Vehicle Car is derived from Vehicle Car is a specialized Vehicle Car is a subclass of Vehicle Car is a derived class of Vehicle Vehicle is the base class of Car Vehicle is the superclass of Car Inheritance Hierarchy * Basic Terminology 2: Polymorphism Original meaning: “Having many forms” The sender of a stimulus doesn’t need to know the receiver’s class. Different receivers can interpret the message in their own way. Consequence: different receivers can response to the same stimulus based on their interpretation. So we can have a variety of objects who process the same piece of data in different ways. Implemented via method overloading and overriding. Override,覆盖是指在子类(c++中的派生类) 中重新定义父类的函数 重载(overload): 在同一个类中,出现多个同名的方法的现象就是Overload ;重载发生在同一个类中,不同方法之间的现象 * 多态的例子 * Basic Terminology 3: Encapsulation Encapsulation is the process of hiding the implementation details of an object. The only access to manipulate the object data is through its interface. It protects an object’s internal state from being corrupted by other objects. Also, other objects are protected from changes in the object implementation. Encapsulation allows objects to be vie

文档评论(0)

xcs88858 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档