docs: adding subject and main

This commit is contained in:
amin 2024-07-02 12:11:43 +01:00 committed by zanninso
parent a611b6704d
commit e514c70648
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,13 @@
public class ExerciseRunner {
public static void main(String[] args) {
Factory factory = new Factory();
// Handle invalid product type
Object invalidProduct = factory.createProduct("C");
if (invalidProduct != null) {
invalidProduct.showDetails();
} else {
System.out.println("Invalid product type");
}
}
}

View File

@ -0,0 +1,60 @@
## 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
```java
// Product interface
public interface Product {
void showDetails();
}
// ConcreteProductA class
public class ConcreteProductA {
...
}
// ConcreteProductB class
public class ConcreteProductB {
...
}
// Factory class
public class Factory {
public ConcreteProductB createProduct(String type) { // the type parametre accept two values `A` and `B`
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your classes:
```java
public class ExerciseRunner {
public static void main(String[] args) {
Factory factory = new Factory();
// Handle invalid product type
Object invalidProduct = factory.createProduct("C");
if (invalidProduct != null) {
invalidProduct.showDetails();
} else {
System.out.println("Invalid product type");
}
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Invalid product type
$
```