TIJ swot_JAVA的初学者(四)

原创 2004年09月16日 00:56:00

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.


1.6.2 Abstract base classes and interfaces

To declare an class abstract, we prevent creating an object of that class.

We can declare a class or a method as abstract, but abstract method can only be created inside an abstract class.

To take the concept of abstract class one step further, we could declare a class as an interface. Any implementation of methods is strictly forbidden in an interface.


TIJ swot_JAVA的初学者(五)

1.7 Object landscapes and lifetimesWell, mentioned something about C++C++ takes the approach that co...
  • Miracle04
  • Miracle04
  • 2004年09月16日 02:32
  • 778

TIJ swot_JAVA的初学者(六)

1.8 Exception handling: dealing with errorsAn exception is an object thrown from the site of the err...
  • Miracle04
  • Miracle04
  • 2004年09月16日 04:27
  • 707

TIJ swot_JAVA的初学者(三)

1.3 The hidden implementationAccess control enables users to solve their particular problems without...
  • Miracle04
  • Miracle04
  • 2004年09月15日 07:00
  • 718

TIJ swot_JAVA的初学者(一)

  • Miracle04
  • Miracle04
  • 2004年09月15日 05:36
  • 862

TIJ swot_JAVA的初学者(二)

  • Miracle04
  • Miracle04
  • 2004年09月15日 06:28
  • 752


Thinking in Java 看了有几个月了,结果在第二遍看完了《控制程序流程》之后,程序才能按自己的意思运行。1、初始化问题:了解变量的初始化,初始化位置。                   ...
  • zhones
  • zhones
  • 2005年04月04日 10:37
  • 578

读TIJ -2 一切都是对象

《Thinking In Java·第2 章一切都是对象》
  • yqj2065
  • yqj2065
  • 2014年07月06日 04:22
  • 1106


心得暨TIJ笔记(原创)1.overridden(覆盖也叫覆写)规则  1).返回类型必须与所重写方法相同  2).不能比所重写方法访问性差  3).不能比所重写方法抛出更多异常2.finally唯一...
  • whoopee
  • whoopee
  • 2005年03月22日 19:24
  • 1103


  • WolfOfSiberian
  • WolfOfSiberian
  • 2014年10月08日 07:54
  • 573


body, td { font-family: 微软雅黑; font-size: 10pt; } ...
  • the_catcher
  • the_catcher
  • 2016年09月03日 23:57
  • 80
您举报文章:TIJ swot_JAVA的初学者(四)