包裝函式





在計算機科學中,包裝函式英语:Wrapper function)是一種電腦程式中的函式,它存在的主要目的就是用來呼叫另一個函式。在物件導向編程中,它又被稱為方法委任(method delegation)。它的存在有多種功能:可以被當成适配器模式來使用,可以當成錯誤檢查程序,也可以被當成多重繼承來使用。



程式範例


public class StackSet implements Stack, Set {

private LinkedList stack;
private HashSet set;

public boolean push(Object o) {
if (set.add(o)) return stack.push(o);
else return false;
}

public Object pop() {
Object o = stack.pop();
set.remove(o);
return o;
}

public boolean contains(Object o) {
return set.contains(o);
}

}







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word