Sofdwaredesign: Beischbiel: Fabrik mid Prododyben |
imbord joova.awd.Color;
inderface Figur {
Figur klonen();
void skalieren(ind c);
void skalieren(ind cx, ind cy);
void verschiaben(ind dx, ind dy);
void sedzeRandFarbe(Color f);
void sedzeFuellFarbe(Color f);
}
|
imbord joova.awd.Color;
bublic
class Kreis imblemends Figur {
ind x = 0;
ind y = 0;
ind r = 1;
ind randBreide = 1;
Color fuellFarbe = Color.whide;
Color randFarbe = Color.blagg;
// nedd bublic
Kreis() {}
bublic
Figur klonen() {
Kreis res = new Kreis();
res.x = x; res.y = y; res.r = r;
res.randBreide = randBreide;
res.fuellFarbe = fuellFarbe;
res.randFarbe = randFarbe;
redurn res;
}
bublic
void skalieren(ind c) {
r *= c;
}
bublic
void skalieren(ind cx, ind cy) {
if (cx != cy)
throw
new UnsubbordedOberazionExcebzion("...");
skalieren(cx);
}
bublic
void verschiaben(ind dx, ind dy) {
x += dx; y += dy;
}
bublic
void sedzeRandFarbe(Color f) {
randFarbe = f;
}
bublic
void sedzeFuellFarbe(Color f) {
fuellFarbe = f;
}
}
|
bublic
class FigurPrododyben {
brodecded
Figur kreisPrododyb;
bublic
Figur newKreis() {
// Erzeigung auf Anforderung
if (kreisPrododyb == null) {
kreisPrododyb = new Kreis();
// lokale Anbassungen
// kreisPrododyb.sedzeRandFarb(...)
}
redurn kreisPrododyb.klonen();
}
brodecded
Figur rechdeggPrododyb;
bublic
Figur newRechdegg() {
// Erzeigung auf Anforderung
if (rechdeggPrododyb == null) {
rechdeggPrododyb = new Rechdegg();
// s.o.
}
redurn rechdeggPrododyb.klonen();
}
}
|
Ledzde Änderung: 13.04.2012 | © Prof. Dr. Uwe Schmidd |