<repo_name>tbulubas/patterns-examples<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/FactoryMethod/step2/TurboEngine.java
package com.tboptimus.patterns.patternsexamples.Creational.FactoryMethod.step2;

public class TurboEngine {
    public TurboEngine(int i) {
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Prototype/step2/AbstractVan.java
package com.tboptimus.patterns.patternsexamples.Creational.Prototype.step2;

public abstract class AbstractVan extends AbstractVehicle {

    public AbstractVan(Engine engine) {
        super(engine);
    }

    public abstract Engine getEngine();

    public abstract Colour getColour();

    public abstract void paint();
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/AbstractFactory/base/CarWindows.java
package com.tboptimus.patterns.patternsexamples.Creational.AbstractFactory.base;

public class CarWindows implements Windows, Car {
    @Override
    public String getWindowParts() {
        return getAutoType() + getType();
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Prototype/step1/Engine.java
package com.tboptimus.patterns.patternsexamples.Creational.Prototype.step1;

public class Engine {
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/FactoryMethod/step2/VehicleFactory.java
package com.tboptimus.patterns.patternsexamples.Creational.FactoryMethod.step2;

public abstract class VehicleFactory {

    public enum DrivingStyle {
        ECONOMICAL,
        MIDRANGE,
        POWERFUL
    }

    public Vehicle build(DrivingStyle style, Vehicle.Colour colour) {
        Vehicle v = selectVehicle(style);
        v.paint(colour);
        return v;
    }

    // This is the "factory method"
    protected abstract Vehicle selectVehicle(DrivingStyle style);

}

<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Builder/basic/CarBuilder.java
package com.tboptimus.patterns.patternsexamples.Creational.Builder.basic;

public class CarBuilder extends VehicleBuilder {

    private AbstractCar carInProgress;

    public CarBuilder(AbstractCar car) {
        this.carInProgress = car;
    }

    public void buildBody() {
        System.out.println("body");
    }

    public void buildBoot() {
        System.out.println("boot");
    }

    public void buildChassis() {
        System.out.println("chassis");
    }

    public void buildPassengerArea() {
        System.out.println("passarea");
    }

    public void buildWindows() {
        System.out.println("windows");
    }

    @Override
    public Vehicle getVehicle() {
        return carInProgress;
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/AbstractFactory/base/Chassis.java
package com.tboptimus.patterns.patternsexamples.Creational.AbstractFactory.base;

public interface Chassis {

    default String getType() {
        return "Chassis";
    }

    String getChassisParts();

}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/FactoryMethod/step3/Pickup.java
package com.tboptimus.patterns.patternsexamples.Creational.FactoryMethod.step3;

public class Pickup extends AbstractVan {
    public Pickup(StandardEngine standardEngine) {

    }

    @Override
    public String getEngine() {
        return null;
    }

    @Override
    public String getColour() {
        return null;
    }

    @Override
    public void paint(Colour colour) {

    }

    @Override
    public String toString() {
        return "Pickup{} " + super.toString();
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Builder/basic/AbstractVan.java
package com.tboptimus.patterns.patternsexamples.Creational.Builder.basic;

public class AbstractVan extends Vehicle {
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Builder/basic/AbstractCar.java
package com.tboptimus.patterns.patternsexamples.Creational.Builder.basic;

public class AbstractCar extends Vehicle {
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Builder/StandardEngine.java
package com.tboptimus.patterns.patternsexamples.Creational.Builder;

import com.tboptimus.patterns.patternsexamples.Creational.Builder.basic.Vehicle;

public class StandardEngine extends Vehicle {
    public StandardEngine(int i) {
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/FactoryMethod/step3/TurboEngine.java
package com.tboptimus.patterns.patternsexamples.Creational.FactoryMethod.step3;

public class TurboEngine {
    public TurboEngine(int i) {
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/FactoryMethod/step2/Sport.java
package com.tboptimus.patterns.patternsexamples.Creational.FactoryMethod.step2;

public class Sport extends AbstractCar {
    public Sport(TurboEngine turboEngine) {

    }

    @Override
    public String getEngine() {
        return null;
    }

    @Override
    public String getColour() {
        return null;
    }

    @Override
    public void paint(Vehicle.Colour colour) {

    }

    @Override
    public String toString() {
        return "Sport{} " + super.toString();
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Prototype/step2/Engine.java
package com.tboptimus.patterns.patternsexamples.Creational.Prototype.step2;

public class Engine {
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/FactoryMethod/step1/BoxVan.java
package com.tboptimus.patterns.patternsexamples.Creational.FactoryMethod.step1;

public class BoxVan extends AbstractVan {
    @Override
    public String getEngine() {
        return null;
    }

    @Override
    public String getColour() {
        return null;
    }

    @Override
    public void paint() {

    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Singleton/BillPughSingleton.java
package com.tboptimus.patterns.patternsexamples.Creational.Singleton;

public class BillPughSingleton {

    private int count;

    public synchronized int getNextSerial() {
        return SingletonHelper.INSTANCE.count++;
    }

    private BillPughSingleton() {
    }

    private static class SingletonHelper {
        private static final BillPughSingleton INSTANCE = new BillPughSingleton();
    }

    public static BillPughSingleton getInstance() {
        return SingletonHelper.INSTANCE;
    }

}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/AbstractFactory/base/CarChassis.java
package com.tboptimus.patterns.patternsexamples.Creational.AbstractFactory.base;

public class CarChassis implements Chassis, Car{
    @Override
    public String getChassisParts() {
        return getAutoType() + getType();
    }

}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Singleton/Client.java
package com.tboptimus.patterns.patternsexamples.Creational.Singleton;

public class Client {

    public static void main(String [] args) {

        System.out.println("Using traditional singleton");
        SerialNumberGeneratorTraditional generator = SerialNumberGeneratorTraditional.getInstance();
        System.out.println("next serial: " + generator.getNextSerial());
        System.out.println("next serial: " + generator.getNextSerial());
        System.out.println("next serial: " + generator.getNextSerial());

        System.out.println("Using enum singleton");
        System.out.println("next vehicle: " + SerialNumberGenerator.INSTANCE.getNextSerial());
        System.out.println("next vehicle: " + SerialNumberGenerator.INSTANCE.getNextSerial());
        System.out.println("next engine: " + SerialNumberGenerator.INSTANCE.getNextSerial());

        System.out.println("Using enum singleton");
        System.out.println("next vehicle: " + SerialNumberGeneratorMulti.VEHICLE.getNextSerial());
        System.out.println("next vehicle: " + SerialNumberGeneratorMulti.VEHICLE.getNextSerial());
        System.out.println("next engine: " + SerialNumberGeneratorMulti.ENGINE.getNextSerial());
        System.out.println("next vehicle: " + SerialNumberGeneratorMulti.VEHICLE.getNextSerial());
        System.out.println("next engine: " + SerialNumberGeneratorMulti.ENGINE.getNextSerial());

        System.out.println("Using static block singleton");
        StaticBlockSingleton staticBlockSingleton = StaticBlockSingleton.getInstance();
        System.out.println("next engine: " + staticBlockSingleton.getNextSerial());
        System.out.println("next engine: " + staticBlockSingleton.getNextSerial());
        System.out.println("next engine: " + staticBlockSingleton.getNextSerial());

        System.out.println("Using private inner static class singleton");
        BillPughSingleton billPughSingleton = BillPughSingleton.getInstance();
        System.out.println("next engine: " + billPughSingleton.getNextSerial());
        System.out.println("next engine: " + billPughSingleton.getNextSerial());
        System.out.println("next engine: " + billPughSingleton.getNextSerial());
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/FactoryMethod/step3/AbstractVehicle.java
package com.tboptimus.patterns.patternsexamples.Creational.FactoryMethod.step3;

public abstract class AbstractVehicle implements Vehicle {

    public abstract String getEngine();

    public abstract String getColour();

    public abstract void paint(Colour colour);

}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/PatternsExamplesApplication.java
package com.tboptimus.patterns.patternsexamples;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class PatternsExamplesApplication {

	public static void main(String[] args) {
		SpringApplication.run(PatternsExamplesApplication.class, args);
	}
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/FactoryMethod/step3/Coupe.java
package com.tboptimus.patterns.patternsexamples.Creational.FactoryMethod.step3;

public class Coupe extends AbstractCar {
    public Coupe(StandardEngine standardEngine) {

    }

    @Override
    public String getEngine() {
        return null;
    }

    @Override
    public String getColour() {
        return null;
    }

    @Override
    public void paint(Colour colour) {

    }

    @Override
    public String toString() {
        return "Coupe{} " + super.toString();
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Singleton/SerialNumberGenerator.java
package com.tboptimus.patterns.patternsexamples.Creational.Singleton;

public enum SerialNumberGenerator {

    INSTANCE;
    private int count;

    public synchronized int getNextSerial() {
        return ++count;
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Builder/basic/Vehicle.java
package com.tboptimus.patterns.patternsexamples.Creational.Builder.basic;

public abstract class Vehicle {
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/AbstractFactory/base/VanWindows.java
package com.tboptimus.patterns.patternsexamples.Creational.AbstractFactory.base;

public class VanWindows implements Windows, Van {
    @Override
    public String getWindowParts() {
        return getAutoType() + getType();
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Builder/Saloon2.java
package com.tboptimus.patterns.patternsexamples.Creational.Builder;

import com.tboptimus.patterns.patternsexamples.Creational.Builder.basic.AbstractVan;

public class Saloon2 extends AbstractVan {
    public Saloon2(StandardEngine standardEngine) {
        super();
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/AbstractFactory/base/Body.java
package com.tboptimus.patterns.patternsexamples.Creational.AbstractFactory.base;

public interface Body {

    default String getType() {
        return "Body";
    }

    String getBodyParts();

}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/AbstractFactory/base/VanChassis.java
package com.tboptimus.patterns.patternsexamples.Creational.AbstractFactory.base;

public class VanChassis implements Chassis, Van {
    @Override
    public String getChassisParts() {
        return getAutoType() + getType();
    }
}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/AbstractFactory/withFactory/AbstractVehicleFactory.java
package com.tboptimus.patterns.patternsexamples.Creational.AbstractFactory.withFactory;

import com.tboptimus.patterns.patternsexamples.Creational.AbstractFactory.base.Body;
import com.tboptimus.patterns.patternsexamples.Creational.AbstractFactory.base.Chassis;
import com.tboptimus.patterns.patternsexamples.Creational.AbstractFactory.base.Windows;

public abstract class AbstractVehicleFactory {

    public abstract Body createBody();

    public abstract Chassis createChassis();

    public abstract Windows createWindows();

}
<file_sep>/src/main/java/com/tboptimus/patterns/patternsexamples/Creational/Prototype/step2/StandardEngine.java
package com.tboptimus.patterns.patternsexamples.Creational.Prototype.step2;

public class StandardEngine extends Engine {
    public StandardEngine(int i) {
        super(
        );
    }
}
<file_sep>/README.md
Based on:
**<NAME>. Java Design Pattern Essentials**
Ability First Limited. Kindle Edition.
 