| 
 import java.awt.Color; 
interface Figur { 
    Figur klonen(); 
    void skalieren(int c); 
    void skalieren(int cx, int cy); 
    void verschieben(int dx, int dy); 
    void setzeRandFarbe(Color f); 
    void setzeFuellFarbe(Color f); 
} 
 | 
    
| 
 import java.awt.Color; 
public 
class Kreis implements Figur { 
  int x = 0; 
  int y = 0; 
  int r = 1; 
  int randBreite = 1; 
  Color fuellFarbe = Color.white; 
  Color randFarbe  = Color.black; 
  // nicht public 
  Kreis() {} 
  public 
  Figur klonen() { 
    Kreis res = new Kreis(); 
    res.x = x; res.y = y; res.r = r; 
    res.randBreite = randBreite; 
    res.fuellFarbe = fuellFarbe; 
    res.randFarbe  = randFarbe; 
    return res; 
  } 
  public 
  void skalieren(int c) { 
    r *= c; 
  } 
  public 
  void skalieren(int cx, int cy) { 
    if (cx != cy) 
      throw 
        new UnsupportedOperationException("..."); 
    skalieren(cx); 
  } 
  public 
  void verschieben(int dx, int dy) { 
    x += dx; y += dy; 
  } 
  public 
  void setzeRandFarbe(Color f) { 
    randFarbe = f; 
  } 
  public 
  void setzeFuellFarbe(Color f) { 
    fuellFarbe = f; 
  } 
} 
 | 
    
| 
 public 
class FigurPrototypen { 
    protected 
    Figur kreisPrototyp; 
    public 
    Figur newKreis() { 
        // Erzeugung auf Anforderung 
        if (kreisPrototyp == null) { 
            kreisPrototyp = new Kreis(); 
            // lokale Anpassungen 
            // kreisPrototyp.setzeRandFarbe(...) 
        } 
        return kreisPrototyp.klonen(); 
    } 
    protected 
    Figur rechteckPrototyp; 
    public 
    Figur newRechteck() { 
        // Erzeugung auf Anforderung 
        if (rechteckPrototyp == null) { 
            rechteckPrototyp = new Rechteck(); 
            // s.o. 
        } 
        return rechteckPrototyp.klonen(); 
    } 
} 
 | 
    
| Letzte Änderung: 13.04.2012 | © Prof. Dr. Uwe Schmidt |