diff --git a/res/lab1_decorator/ex1.png b/res/lab1_decorator/ex1.png deleted file mode 100644 index 6ef181d..0000000 Binary files a/res/lab1_decorator/ex1.png and /dev/null differ diff --git a/res/lab1_decorator/ex2.png b/res/lab1_decorator/ex2.png deleted file mode 100644 index 65fa1f2..0000000 Binary files a/res/lab1_decorator/ex2.png and /dev/null differ diff --git a/src/lab2_factory_method/ex1/Car.java b/src/lab2_factory_method/ex1/Car.java new file mode 100644 index 0000000..0016f7c --- /dev/null +++ b/src/lab2_factory_method/ex1/Car.java @@ -0,0 +1,13 @@ +package lab2_factory_method.ex1; + +public abstract class Car { + private String color; + + public Car(String color) { + this.color = color; + } + public abstract String getName(); + public String getColor() { + return color; + }; +} diff --git a/src/lab2_factory_method/ex1/CarCreator.java b/src/lab2_factory_method/ex1/CarCreator.java new file mode 100644 index 0000000..a1244a2 --- /dev/null +++ b/src/lab2_factory_method/ex1/CarCreator.java @@ -0,0 +1,5 @@ +package lab2_factory_method.ex1; + +public abstract class CarCreator { + public abstract Car orderCar(String color); +} diff --git a/src/lab2_factory_method/ex1/Coupe.java b/src/lab2_factory_method/ex1/Coupe.java new file mode 100644 index 0000000..869a0c0 --- /dev/null +++ b/src/lab2_factory_method/ex1/Coupe.java @@ -0,0 +1,11 @@ +package lab2_factory_method.ex1; + +public class Coupe extends Car { + public Coupe(String color) { + super(color); + } + + public String getName() { + return "Coupe"; + } +} diff --git a/src/lab2_factory_method/ex1/CoupeCreator.java b/src/lab2_factory_method/ex1/CoupeCreator.java new file mode 100644 index 0000000..de22852 --- /dev/null +++ b/src/lab2_factory_method/ex1/CoupeCreator.java @@ -0,0 +1,9 @@ +package lab2_factory_method.ex1; + +public class CoupeCreator extends CarCreator { + + @Override + public Car orderCar(String color) { + return new Coupe(color); + } +} diff --git a/src/lab2_factory_method/ex1/Minivan.java b/src/lab2_factory_method/ex1/Minivan.java new file mode 100644 index 0000000..d9b9944 --- /dev/null +++ b/src/lab2_factory_method/ex1/Minivan.java @@ -0,0 +1,12 @@ +package lab2_factory_method.ex1; + +public class Minivan extends Car { + public Minivan(String color) { + super(color); + } + + @Override + public String getName() { + return "Minivan"; + } +} diff --git a/src/lab2_factory_method/ex1/MinivanCreator.java b/src/lab2_factory_method/ex1/MinivanCreator.java new file mode 100644 index 0000000..d7ae29e --- /dev/null +++ b/src/lab2_factory_method/ex1/MinivanCreator.java @@ -0,0 +1,8 @@ +package lab2_factory_method.ex1; + +public class MinivanCreator extends CarCreator { + @Override + public Car orderCar(String color) { + return new Minivan(color); + } +} diff --git a/src/lab2_factory_method/ex1/Pickup.java b/src/lab2_factory_method/ex1/Pickup.java new file mode 100644 index 0000000..5d50c87 --- /dev/null +++ b/src/lab2_factory_method/ex1/Pickup.java @@ -0,0 +1,12 @@ +package lab2_factory_method.ex1; + +public class Pickup extends Car { + public Pickup(String color) { + super(color); + } + + @Override + public String getName() { + return "Pickup"; + } +} diff --git a/src/lab2_factory_method/ex1/PickupCreator.java b/src/lab2_factory_method/ex1/PickupCreator.java new file mode 100644 index 0000000..b58b8b7 --- /dev/null +++ b/src/lab2_factory_method/ex1/PickupCreator.java @@ -0,0 +1,8 @@ +package lab2_factory_method.ex1; + +public class PickupCreator extends CarCreator { + @Override + public Car orderCar(String color) { + return new Pickup(color); + } +} diff --git a/src/lab2_factory_method/ex1/Program.java b/src/lab2_factory_method/ex1/Program.java new file mode 100644 index 0000000..d11e419 --- /dev/null +++ b/src/lab2_factory_method/ex1/Program.java @@ -0,0 +1,21 @@ +package lab2_factory_method.ex1; + +public class Program { + public static void main(String[] args) { + CarCreator coupeCreator = new CoupeCreator(); + CarCreator minivanCreator = new MinivanCreator(); + CarCreator pickupCreator = new PickupCreator(); + Car c1 = coupeCreator.orderCar("red"); + System.out.println("Car " + + c1.getName() + + " " + + c1.getColor() + + " has been ordered."); + Car c2 = minivanCreator.orderCar("red"); + System.out.println("Car " + + c2.getName() + + " " + + c2.getColor() + + " has been ordered."); + } +} \ No newline at end of file diff --git a/src/learn/simple_factory_method/ConcreteCreator.java b/src/learn/simple_factory_method/ConcreteCreator.java new file mode 100644 index 0000000..fe8c58e --- /dev/null +++ b/src/learn/simple_factory_method/ConcreteCreator.java @@ -0,0 +1,8 @@ +package learn.simple_factory_method; + +public class ConcreteCreator extends Creator { + @Override + public Product factoryMethod() { + return new ConcreteProduct("Product"); + } +} diff --git a/src/learn/simple_factory_method/ConcreteProduct.java b/src/learn/simple_factory_method/ConcreteProduct.java new file mode 100644 index 0000000..251de5b --- /dev/null +++ b/src/learn/simple_factory_method/ConcreteProduct.java @@ -0,0 +1,14 @@ +package learn.simple_factory_method; + +public class ConcreteProduct implements Product { + private String category; + + public ConcreteProduct(String category) { + this.category = category; + } + + @Override + public String toString() { + return "ConcreteProduct('" + category + "')"; + } +} diff --git a/src/learn/simple_factory_method/Creator.java b/src/learn/simple_factory_method/Creator.java new file mode 100644 index 0000000..8aba44d --- /dev/null +++ b/src/learn/simple_factory_method/Creator.java @@ -0,0 +1,10 @@ +package learn.simple_factory_method; + +public abstract class Creator { + abstract public Product factoryMethod(); + + public void anOperation() { + Product product = this.factoryMethod(); + System.out.println("Do something with product " + product); + } +} diff --git a/src/learn/simple_factory_method/Main.java b/src/learn/simple_factory_method/Main.java new file mode 100644 index 0000000..0830a96 --- /dev/null +++ b/src/learn/simple_factory_method/Main.java @@ -0,0 +1,8 @@ +package learn.simple_factory_method; + +public class Main { + public static void main(String[] args) { + Creator creator = new ConcreteCreator(); + creator.anOperation(); + } +} diff --git a/src/learn/simple_factory_method/Product.java b/src/learn/simple_factory_method/Product.java new file mode 100644 index 0000000..286fa06 --- /dev/null +++ b/src/learn/simple_factory_method/Product.java @@ -0,0 +1,4 @@ +package learn.simple_factory_method; + +public interface Product { +}