You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
amin 6f4f10e010 docs: change the main file to be aling with the subject 4 months ago
..
ExerciseRunner.java docs: change the main file to be aling with the subject 4 months ago
README.md docs: adding more test examples 4 months ago

README.md

Factory Blueprint

Instructions

You are given an incomplete Factory design pattern implementation with some incorrect parts. Complete and fix the class to demonstrate your understanding of how the Factory design pattern works.

Expected Classes

// Product interface
public interface Product {
    void showDetails();
}

// ConcreteProductA class
public class ConcreteProductA {
    ...
}

// ConcreteProductB class
public class ConcreteProductB {
    ...
}

// Factory class
public class Factory {
    public Product createProduct(String type) {

    }
}

Usage

Here is a possible ExerciseRunner.java to test your classes:

public class ExerciseRunner {
    public static void main(String[] args) {
        Factory factory = new Factory();

        ConcreteProductA productA = factory.createProduct("A");
        if (productA != null) {
            productA.showDetails();
        } else {
            System.out.println("Invalid product type");
        }

        ConcreteProductA productB = factory.createProduct("B");
        if (productB != null) {
            productB.showDetails();
        } else {
            System.out.println("Invalid product type");
        }

        Object invalidProduct = factory.createProduct("C");
        if (invalidProduct != null) {
            invalidProduct.showDetails();
        } else {
            System.out.println("Invalid product type");
        }
    }
}

Expected Output

$ javac *.java -d build
$ java -cp build ExerciseRunner
This is ConcreteProductA.
This is ConcreteProductB.
Invalid product type
$