PYTANIE 1
Jeśli chcę produkować różne Scrappery o różnych atrybutach fabryką/fabrykami to lepiej zrobić osobną fabrykę dla każdego Scrappera, a w niej różne metody implementacji tego Scrappera?
np. Scrapper wyszukujący wiek to inny scrapper niż wyszukujący rasę albo płeć. Ale każdy z nich może być zaimplementowany np. w sposób defaultowy, ryzykowny (dużo łapie, ale więcej błędów) albo ostrożny (mało łapie, ale mniej błędów).
class ScrapperSexFactory implements ScrapperDefaultFactory, ScrapperRiskyFactory, ScrapperSafeFactory {
Scrapper produceDefault() {
}
Scrapper produceRisky() {
}
Scrapper produceSafe() {
}
}
class ScrapperRaceFactory implements ScrapperDefaultFactory, ScrapperRiskyFactory, ScrapperSafeFactory {
Scrapper produceDefault() {
}
Scrapper produceRisky() {
}
Scrapper produceSafe() {
}
}
czy:
class ScrapperSexFactory implements ScrapperDefaultSexFactory, ScrapperRiskySexFactory, ScrapperSafeSexFactory, ScrapperDefaultRaceFactory, ScrapperRiskyRaceFactory, ScrapperSafeRaceFactory {
Scrapper produceDefaultSex() {
}
Scrapper produceRiskySex() {
}
Scrapper produceSafeSex() {
}
Scrapper produceDefaultRace() {
}
Scrapper produceRiskyRace() {
}
Scrapper produceSafeRace() {
}
}
a może tak:
class ScrapperDefaultFactory implements ScrapperAgeFactory, ScrapperSexFactory, ScrapperRaceFactory {
Scrapper produceAge() {
}
Scrapper produceSex() {
}
Scrapper produceRace() {
}
}
class ScrapperRiskyFactory ScrapperAgeFactory, ScrapperSexFactory, ScrapperRaceFactory {
Scrapper produceAge() {
}
Scrapper produceSex() {
}
Scrapper produceRace() {
}
}
class ScrapperSafeFactory ScrapperAgeFactory, ScrapperSexFactory, ScrapperRaceFactory {
Scrapper produceAge() {
}
Scrapper produceSex() {
}
Scrapper produceRace() {
}
}
PYTANIE 2
jak implementować factory? Samymi metodami zamkniętymi na modyfikacje czy metodami z argumentami czy może po atrybutach klasy które można ustawiać setterami?
class Factory {
Object produce1() {
// ...
// ... producing
// ...
}
Object produce2() {
// ...
// ... producing
// ...
}
}
czy:
class Factory {
Object produce(arg1, arg2, arg3, arg4, arg5) {
// ...
// ... producing using args
// ...
}
}
czy:
class Factory {
arg1 = //... default implementation;
arg2 = //... default implementation;
arg3 = //... default implementation;
arg4 = //... default implementation;
arg5 = //... default implementation;
Object produce() {
// ...
// ... producing using this.args
// ...
}
// ...
// ... public setters of args
// ...
}