BillBundle
в качестве объекта параметра представляет собой масштабируемый подход для сокращения списка параметров методов. Как и любая реализация шаблона проектирования объекта параметра , подразумевает также перемещение по коду, обрабатывающему параметры. Опция, позволяющая избежать дублирования кода при получении счетов и передачи их таким методам, как depositCash
, может быть совмещена между шаблоном дизайна посетителя для получения счетов и шаблоном разработки метода шаблона обрабатывать их
Предполагая, что информация, используемая для расчета счетов, поступает из банкомата, эмитент счета может вычислить счета и принять в качестве посетителя обработчик счета, который получает счета и обрабатывает их
interface BillEmitter {
int getFives();
int getTens();
int getTwenties();
int getFifties();
default void accept(Visitor v) {
v.visit(this);
}
}
// add BillEmitter implementations as needed
public class SomeBillEmitter implements BillEmitter {
private Atm atm;
public SomeBillEmitter(Atm atm) {
this.atm = atm;
}
public int getFives() {
int theFivesBill = 0;
// compute the fives bill with the information from ATM
return theFivesBill;
}
public int getTens() {
int theTensBill = 0;
// compute the tens bill with the information from ATM
return theTensBill;
}
public int getTwenties() {
int theTwentiesBill = 0;
// compute the twenties bill with the information from ATM
return theTwentiesBill;
}
public int getFifties() {
int theFiftiesBill = 0;
// compute the fifties bill with the information from ATM
return theFiftiesBill;
}
}
Посетители
interface Visitor {
default void visit(BillEmitter billEmitter) {
// template method which gets the bills from the billEmitter
// and pass them to the bill processor
Billbundle billBundle = new BillBundle();
billBundle.setFives(billEmitter.getFives());
billBundle.setTens(billEmitter.getTens());
billBundle.setTwenties(billEmitter.getTwenties());
billBundle.setFifties(billEmitter.getFifties());
processBills(billBundle);
}
void processBills(BillBundle billBundle);
}
// add Visitor implementations as needed
public class DepositCashVisitor implements Visitor {
public void processBills(BillBundle billBundle) {
// deposit the cash
...
}
}
Использование
public class Atm {
// add methods which returns information used to emit bills
}
public class Test {
public static void main(String[] args) {
Visitor depositCashVisitor = new DepositCashVisitor();
Atm atm = new Atm();
BillEmitter billEmitter = new SomeBillEmitter(atm);
billEmitter.accept(depositCashVisitor);
// add more bill emitters and visit them with depositCashVisitor
// or add more visitors and visit billEmitter with them
}
}
После поиска некоторое время я нашел решение в нескольких блогах, таким образом, благодаря Pablo и Shimi. Они содержат более подробный фон, если Вам интересно.
Проблема, связанная с чем-то позвонившим Контроллер Агента, связываемый со старой версией libstdc ++. Для решения его, можно выполнить следующие две команды:
wget mirrors.kernel.org/ubuntu/pool/universe/g/gcc-2.95/libstdc++2.10-glibc2.2_2.95.4-24_i386.deb
sudo dpkg --install libstdc++2.10-glibc2.2_2.95.4-24_i386.deb
Хотя Ваш пробег может варьироваться в зависимости от версии дистрибутива и т.д.
Необходимо затем смочь представить успешно в Eclipse, я нашел, что не должен был даже перезапускать Eclipse.
Проблема: необходимо установить libstdc ++ - libc6.2-2.so.3. Для решения этой проблемы в openSUSE установите пакет "compat".
Используйте следующее, если вы используете Ubuntu 9.10 Karmic Koala, 64 бит
wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-3.3/libstdc++5_3.3.6-17ubuntu1_amd64.deb
sudo dpkg -i libstdc++5_3.3.6-17ubuntu1_amd64.deb
Запустите eclipse и viola ... вы в деле :)