看板java
标 题Re: [问题] 想请问interface的具体意义
发信站政大狂狷年少 (Tue Jan 23 13:00:12 2007)
转信站ptt!ctu-reader!ctu-gate!news.nctu!newsfeed.nthu!news.cs.nthu!WHSHS
※ 引述《[email protected] (泼文章都是为了养小鸡)》之铭言:
> 是这样子的,我是C++的使用着
> 在阅读SoftwareSolutions书籍或文章的时候
> 常常会看见JAVA的interface
> 我可以理解interface存在的立场
> 但我更想知道interface更具体的使用....
> (或者,用C++的观念去理解...... if it is possible)
其实在 OO 设计上,
abstract class 常用来当物种家族的 base class,
而 interface 则是常用来当行为 (或演算法) 家族的 base class,
因为物种本身会有预设行为,
而行为本身又有预设行为是很奇怪的一件事,
所以使用 strategy pattern 的设计,
常会看到 abstract class 对一堆 interface 有 has-a 的关系。
在解关系耦合的角度上来看,
因为 abstract class 会存在一些实作码,
所以它可能会直接和其它 class 相依,
但 interface 本身并没有实作码,
所以 interface 几乎只会被其它 class 相依,
自己本身几乎不相依於其它 class,
最多是 method 参数型别会相依其它 class,
而这种 class 通常也是一个 interface。
至於把耦合关系解开能有什麽好处,
我想这个应该就不必我多说了。
--
Name: Tseng, Ling-hua E-mail Address:
[email protected]
School: National Tsing Hua University Department: Computer Science
Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design
Researching: Software pipelining for VLIW architectures
Homepage:
https://it.muds.net/~uranus
--
╔═══╗ ┼────────────────────────╮
║狂狷 ║ │
* Origin:[ 狂 狷 年 少 ] whshs.cs.nccu.edu.tw ╰─╮
║ 年少║ ┼╮
< IP:140.119.164.252 > ╰─╮
╚╦═╦╝ ╰
* From:61-230-224-125.dynamic.hinet.net
─╨─╨─ KGBBS ─ ◎ 遨翔"BBS"的狂狷不驯;属於年少的轻狂色彩 ◎
[修改]tinlans:61-230-224-125.dynamic.hinet.net 07/01/23 13:00:12