设为首页 加入收藏

TOP

TIJ swot_JAVA的初学者(四)
2011-06-09 12:51:24 来源: 作者: 【 】 浏览:574次 评论:0
1.4 Reusing the implementation
We could reuse a class by instantiate it as an obect or place an object of this class inside a new class(this is called composition or aggregation).
1.5 Inheritance: reusing the interface
Inheritance enables us to clone an existing class and make additions and modifications to the clone.The modified “clone” will reflects the change in the original class.Do we need to modify the clone class?
Inheritance represents a certain kind of relationship between classes/types using the concept of base types and derived types. A base type contains all of the characteristics and behaviors that are shared among the types derived from it.
By inheritance, we could add new function to the interface or change the behavior of an existing base-class function.This referred to as overriding that function.
1.5.1 Is-a vs. is-like-a relationship
If inheritance override only base-class function, this is a pure substitution.Like “a circle is a shape“.
When we add new interface elements to a derived type, this substitution isn't perfect.This can be described as an is-like-a relationshipe. Such as “heap pump is like a cooling system".
1.6 Interchangeable objects with polymorphism
By inheritance, we could create a lot more new objects, which has similarities as the base objects. But is that all?
Let me think...We got too many methods or functions have the same name or identification as a result of inheritance. Polymorphism is the mechanism of OOP to pick up the right one automatically. But we dont need to know how it does this at this stage.
In a non-OOP compiler, the function call generated is early binding, that means the absolute address is needed. In OOP, the program cannot determine the affress of the code until run-time. This concept is called late binging. To perform this, Java uses a special bit of code in lieu of the absolute call. This code calculates the address of the function body, using information stored in the object.This is Java's dynamic binding.
您看到此篇文章时的感受是:
Tags: 责任编辑:administrator
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到QQ空间
分享到: 
上一篇Java入门笔记7_Stream 下一篇Java的网络功能与编程 一

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

相关栏目

最新文章

图片主题

热门文章

推荐文章

相关文章

广告位