欢迎来到麦多课文档分享! | 帮助中心 海量文档,免费浏览,给你所需,享你所想!
麦多课文档分享
全部分类
  • 标准规范>
  • 教学课件>
  • 考试资料>
  • 办公文档>
  • 学术论文>
  • 行业资料>
  • 易语言源码>
  • ImageVerifierCode 换一换
    首页 麦多课文档分享 > 资源分类 > PPT文档下载
    分享到微信 分享到微博 分享到QQ空间

    Chapter 10- Data Abstraction and Object Orientation.ppt

    • 资源ID:379514       资源大小:216KB        全文页数:43页
    • 资源格式: PPT        下载积分:2000积分
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    二维码
    微信扫一扫登录
    下载资源需要2000积分(如需开发票,请勿充值!)
    邮箱/手机:
    温馨提示:
    如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如需开发票,请勿充值!如填写123,账号就是123,密码也是123。
    支付方式: 支付宝扫码支付    微信扫码支付   
    验证码:   换一换

    加入VIP,交流精品资源
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    Chapter 10- Data Abstraction and Object Orientation.ppt

    1、1,Chapter 10: Data Abstraction and Object Orientation,Aaron Bloomfield CS 415 Fall 2005,2,Fundamental OO Concepts,Encapsulation Inheritance Dynamic Method Binding,3,Encapsulation,Encapsulation Encapsulation allows the programmer to group data and the subroutines that operate on them together in one

    2、place, and to hide irrelevant details from the user.Information Hiding Making objects and algorithms invisible to portions of the system that do not need them.,4,Modules,If a module M exports a type T, the rest of the program can only pass T to subroutines exported from M. T is said to be an opaque

    3、type.var Database : moduleexports (tuple with (:=, name)type tuple = recordvar name : packed array 180 of charend tuple What can the code outside the Database module do?,5,Module Changing,Body is ChangedPrivate Part of Header is ChangedPublic Part of Header is Changed,It is a change to the interface

    4、 which will often require a user code change,May require user recompile, but never requires a change in user code.,Will never require a change or recompile of the user code,6,Classes can limit visibility,PrivateProtectedPublicPackage (in some languages, e.g. Java),Visible inside the classs methods,V

    5、isible inside the methods of the class and its descendants.,Visible anywhere the class declaration is in scope,7,Derived class can restrict visibility,Private Protected and public members of base class are private in derived class. Protected Protected and public members of base class are protected i

    6、n derived class. Public Protected and public members of base class are protected and public in derived class. Private members of base class arent visible in derived class.,8,Initialization and Finalization,9,Four Important Issues,Choosing a Constructor References and Values Execution Order Garbage C

    7、ollection Weve seen that already,10,Choosing a Constructor,Object-Oriented Languages allow classes to have zero, one or more different constructors. Two ways to distinguish between constructors Different Names Different Number and Types of Arguements,11,Constructors,Eiffel code:class COMPLEXcreation

    8、new_cartesian, new_polarnew_cartesian(x_val, y_va; : REAL) isnew_polar(rho, theta : REAL) is class mydata public:mydata(string data);mydata(int data);mydata();,12,References and Values,C+ vs. Java Java uses reference, C+ you can specify Reference Every object is created explicitly so it is easy to m

    9、ake sure the correct constructor is called. More elegant, but requires allocation from heap and extra indirections on every access of the object. Value More efficient but harder to control initialization,13,Execution Order,If class B is derived from class A, A constructor is called before B construc

    10、tor To get arguments to the A constructor, you must use an intializer listclass foo : bar .foo:foo (foo_params) : bar(bar_params) The part after the colon is a call to bars constructor,14,Destructors and Garbage Collection,When an object is destroyed, the destructor is called for the derived class f

    11、irst, then the destructors of the base classes are called. Reverse order of derivation Destructors purpose is to return allocated space back to the heap Many languages provide automatic garbage collection Java, Smalltalk, Eiffel, etc.,15,Javas finalize() method,In Java, you can override the finalize

    12、() method This allows code to be executed when the object is about to be deleted But you shouldnt extend the objects lifetime by doing this As the finalize() method is only called once per object,16,Dynamic Method Binding,17,Polymorphism,A derived class (D) has all the members of its base class (C)

    13、Class D can be used anytime class C is expected. If class D does not hide any publicly visible members of C then D is a subtype of C. If class D is used in place of class C, this is a form of polymorphism.,18,Polymorphism Example,class person class student : public person class professor : public pe

    14、rson student s; professor p; person *x = ,19,Dynamic vs. Static binding,Static method binding uses the type of the reference: s.print_mailing_label(); p.print_mailing_label(); Dynamic method binding uses the class of the object that is referred/pointed to: x-print_mailing_label(); y-print_mailing_la

    15、bel();,20,Which one does Java use?,public class Foo public String toString() return “Foos toString()“;public static void main (String args) Object bar = new Foo();System.out.println (bar); Java uses dynamic binding,21,Dynamic method binding,Dynamic method binding: calls to virtual methods are dispat

    16、ched to the appropriate implementation at run time based on the class of the object Simula: virtual methods listed at beginning of class declaration CLASS Person; VIRTUAL: PROCEDURE PrintMailingLabel; BEGIN END Person;,22,Dynamic method binding,C+: keyword “virtual” prefixes function declaration cla

    17、ss person public: virtual void print_mailing_label (); This requires keeping a virtual method table along with each object More on this in a bit,23,Abstract Methods,Bodyless virtual methods In C+: called pure virtual method, created by following a procedure declaration with an assignment to zero.cla

    18、ss person public: virtual void print_mailing_label() = 0;,24,Abstract Classes,Class that contains one or more abstract methods Java: called an interface (which has only abstract methods) Generally not possible to declare object of an abstract class b/c it would be missing at least one member But you

    19、 can do so in C+ Serves as a base for concrete classes. Concrete class must provide a definition for every abstract method it inherits Application to dynamic method binding: allows code that calls methods of objects of a base class, assuming that the concrete methods will be invoked at run time.,25,

    20、Member Lookup: vtable,In dynamic binding each object is represented with a record whose first field contains the address of a virtual method table (vtable) for that objects classOur objects are being more complicated for the compiler to manage Virtual method tables Reference counts Etc,26,Member Loo

    21、kup- vtable,27,Single Inheritance,28,Multiple Inheritance,29,Multiple Inheritance,Derived class with two or more base classes E.g. - Student class C+: class student : public person, public gp_list_node ,30,Multiple Inheritance,Supported in C+, Eiffel, CLOS Single Inheritance only in Simula, Smalltal

    22、k, Modula-3, Ada 95 & Oberon Java provides limited support more on this later,31,Why use MI?,Involves a number of tradeoffs Complexity vs. Simplicity Efficiency vs. Scalability How do you decide? Does it satisfy the “is a” relationship? Is object creation speed a constraint?,32,Multiple inheritance

    23、types,Normal (non-repeated) Repeated Shared Mix-in,33,Normal (non-repeated) MI,Recall “views” of objects data members vtables Compile-time constant offset d,34,35,Efficiency (or lack thereof),May have to determine view dynamically Results in less time-efficient code An example implementation may hav

    24、e: 3 extra cycles, 1 extra memory access over single inheritance 5 extra cycles, 3 extra memory accesses over static methods,36,Semantic Ambiguities,What if two base classes have implementations of a shared method? Wont work in Eiffel or C+ In other languages, you must call methods explicitly, i.e.

    25、class:method(),37,Semantic Ambiguities,What if the relationship below occurs?This is repeated multiple inheritance As one of the ancestors is repeated in the parent class of one of the descendents,gp_list_node,person,student,gp_list_node,student_prof,professor,38,Replicated Multiple Inheritance,Defa

    26、ult in C+ Ex. gp_list_node Can only directly access one level deep To access a student view of gp_list_node, you must first assign a student_prof pointer into a student or professor pointer,39,40,Shared Multiple Inheritance,Default in Eiffel Ex. Person Still have problem when inheriting overridden m

    27、ethods,41,42,Mix-in Inheritance,Only one base class can contain method definitions The other base class(es) contain only abstract methods Only type of MI supported in Java, but not necessarily MI Traditional Java inheritance uses keyword extends Mix-in (interface) inheritance in Java uses keyword implements Done via interfaces,43,Java Interfaces,public class String extends Object implements Serializable, CharSequence, Comparable;Java interfaces can contain definition prototypes and static variables,


    注意事项

    本文(Chapter 10- Data Abstraction and Object Orientation.ppt)为本站会员(赵齐羽)主动上传,麦多课文档分享仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文档分享(点击联系客服),我们立即给予删除!




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1 

    收起
    展开