component.java~3~
来自「《深入浅出设计模式》的完整源代码」· JAVA~3~ 代码 · 共 41 行
JAVA~3~
41 行
package composite;
import java.lang.*;
public abstract class Component {
// la classe Component implementa sia l'interfaccia di Leaf che di Composite
public Component(String aName){
name = aName;
}
// questa \uFFFD l'operazione, che il Leaf implementer\uFFFD direttamente
// mentre il Composite delegher\uFFFD ai suoi componenti
public abstract void printName();
// questa \uFFFD l'interfaccia di gestione dei figli.
// \uFFFD stato implementato un controllo sfruttando il DP
// Marker Interface per evitare che i Leaf tentino di aggiungere o rimuovere
// figli.
public void add(Component c){
// if (this instanceof LeafInterface){
// throw new LeafException("Method don't support");
}
public void remove(Component c){
// if (this instanceof LeafInterface){
// throw new LeafException("Method don't support");
}
// questa operazione invece pu\uFFFD anche avere un senso, come da
// punto 3 del GoF. Comunque, una volta implementata la soluzione
// MarkerInterface, anche getChild() potrebbe sollevare un'eccezione
public Component getChild(int n){
return null;
}
// il solito attributo, pubblico per semplificare il codice
public String name;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?