As a quick introduction to implementing design patterns, you will complete a program that adds and multiplies generic objects together using the Factory and Strategy patterns.

The project

You may download the project here: DesignPatterns.zip

Inside, you will find an IntelliJ/Maven project with the following files:

App.java

The main file with a small amount of "test" code.

ArtifactFactory.java

A builder of "artifacts" which currently include two types of numbers.

Context.java

The Strategy holder. This keeps track of what operation is currently in use.

DoubleArtifact.java

A concrete Artifact class representing doubles.

IArtifact.java

The interface that allows all artifacts to be used interchangeably.

IOperation.java

The interface that allows all operations to be used interchangeably.

IntArtifact.java

A concrete Artifact class representing integers.

Product.java

A concrete strategy/operation class that performs a running summation.

Sum.java

A concrete strategy/operation class that performs a running product.

What to do

You must complete the following:

ArtifactFactory.java

Construct the proper type of artifact when requested.

Context.java

Execute the proper strategy when requested.

IntArtifact.java and DoubleArtifact.java

Complete representations of each of these types and complete their conversions. Implement a toString method!

Sum.java and Product.java

Implement the respective operations and complete the constructors. You should always return a new artifact from each operation. You should not promote IntArtifact types unless necessary.

Reminder

You can inspect the type of an interface object using the instanceof operator. Like the following:

Integer a = 34;
Double b = 46.0;
Double res = a*b;

if (res instanceof Number) {
    System.out.println("It's a number!");
}

What to turn in

Attach a zip file in the Canvas assignment.

  1. All files zipped.

  2. A short 1-2 paragraph explanation about what is accomplished with these design patterns.