Skip to content

Latest commit

 

History

History
102 lines (66 loc) · 1.76 KB

File metadata and controls

102 lines (66 loc) · 1.76 KB

Java-Factory

This is designed to be a fairly intuitive example usage of the Factory pattern, using hopefully what is a familiar concept to many: Minecraft mobs.

The goal here isn't to have code that actually does anything functionally. Just to show an example of how the Factory pattern can be applied.

Installation

Well, you need Java.

brew install openjdk@21

This gets OpenJDK Java21 and installs it.

You can check that you're running Java21 by running:

java --version;

A Mac may already have a version of Java installed in /usr/bin/java. You'll be able to tell by running:

which java;

If that outputs /opt/homebrew/opt/openjdk@21/bin then you're golden. If not, you may need to play a little in ~/.zshrc.

Appending to your $path array should work:

path+=("/opt/homebrew/opt/openjdk@21/bin");

If that doesn't, you can ensure that it's prepended before the standard Mac installed version:

path=("$(brew --prefix openjdk@21)/bin" $path)

I've also used Maven, as that's a fairly standard choice.

brew install mvn;

Check that's okay by running:

mvn --version;

I then ran the following Maven command to initialise the repo:

mvn archetype:generate -DgroupId=com.example \
  -DartifactId=console-app \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DinteractiveMode=false

Running

Build

Navigate into the app:

cd console-app

and then run:

mvn package

Run

java -cp target/console-app-1.0-SNAPSHOT.jar com.example.App

Run tests

mvn test

or for a specific test:

mvn -Dtest=AppTest test

Dependencies

  • Mockito (for testing)
  • Guice (for dependency injection)