Cours Génie logiciel
-
Cours :
- Notions programmation orientée objet et Java (pdf)
- Tests (pdf)
- Principes SOLID (pdf)
- Patrons de conception (pdf)
-
Planches de TD :
- TD 1 (pdf), Corrigé TD 1 (pdf)
- TD 2 (pdf), Corrigé TD 2 (pdf)
- TP 1 (pdf), Corrigé TP 1 (pdf)
TP 3 : Adapter
Tâche 1 : Complétez la classe
FrenchPainter
dans le packagefrench
qui implémente l’interfacePainter
.
package french;
import javafx.scene.canvas.GraphicsContext;
import viewer.Painter;
public class FrenchPainter implements Painter {
;
GraphicsContext graphicsContextpublic FrenchPainter(GraphicsContext graphicsContext) {
this.graphicsContext = graphicsContext;
}
public void drawRectangle(double xUpperLeft, double yUpperLeft, double width, double height) {
.strokeRect(xUpperLeft, yUpperLeft, width, height);
graphicsContext}
public void drawCircle(double xCenter, double yCenter, double radius) {
.strokeOval(xCenter-radius,yCenter-radius,2*radius,2*radius);
graphicsContext}
}
Tâche 2 : Proposez une implémentation de la classe
EnglishPainterAdapter
qui ne demande aucune modification du code existant.
package english;
import viewer.Painter;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
public class EnglishPainterAdapter implements Painter {
;
EnglishPainter englishPainter
public EnglishPainterAdapter(GraphicsContext graphicsContext) {
= new EnglishPainter(graphicsContext);
englishPainter }
@Override
public void drawRectangle(double x, double y, double w, double h) {
.paintRectangle(new Point2D(x,y),new Point2D(x+w,y+h));
englishPainter}
@Override
public void drawCircle(double x, double y, double radius) {
.paintCircle(new Point2D(x,y), new Point2D(x+radius,y));
englishPainter}
}