DESIGNER PATTERN FACTORY METHOD EM JAVA COM EXEMPLOS

แชร์
ฝัง

ความคิดเห็น • 2

  • @wmatheushenriq
    @wmatheushenriq 2 ปีที่แล้ว +2

    Mt obrigado, meu amigo. Muito simples

  • @programacaojajava
    @programacaojajava 2 ปีที่แล้ว +7

    Show de boa! Adaptei a factory removendo os ifs:
    public class PolygonFactory {
    private static final Map polygons = Map.ofEntries(
    entry(3, new Triangle()),
    entry(4, new Square()),
    entry(5, new Pentagon())
    );
    public static Polygon createPolygon(int numberOfSides) {
    if (!polygons.containsKey(numberOfSides)) {
    throw new IllegalArgumentException("Invalid number of sides!");
    }
    return polygons.get(numberOfSides);
    }
    }