Everyone did super well, and overall happy with how we went. Here is some general feedback for improvement:
sat1.getType().equals("RelaySatellite")
sat1 instanceof RelaySatellite
If you want more feedback, just ask me or Sophia in the lab
In groups, determine a possible pattern that could be used to solve each of the following problems:
In groups, determine a possible pattern that could be used to solve each of the following problems:
In groups, determine a possible pattern that could be used to solve each of the following problems:
In groups, determine a possible pattern that could be used to solve each of the following problems:
In groups, determine a possible pattern that could be used to solve each of the following problems:
In groups, determine a possible pattern that could be used to solve each of the following problems:
What is it?
Composite is a structural design pattern that lets you compose objects into tree structures and then work with these structures as if they were individual objects.
When should we use it?
Design for type safety: Only one child-related operation in Composite class
Design for Uniformity: Include all child-related operations in the Composite interface.
Inside src/calculator
, use the Composite Pattern to write a simple calculator that evaluates an expression. Your calculator should be able to:
{1 + [2 * (4 + 3)]}
Expression 1
Expression 2
Expression 3
What is it?
Factory Method is a creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alter the type of objects that will be created.
When should we use it?
Inside src/thrones
, there is some code to model a simple chess-like game. In this game different types of characters move around on a grid fighting each other. When one character moves into the square occupied by another they attack that character and inflict damage based on random chance. There are four types of characters:
We want to refactor the code so that when the characters are created, they are put in a random location in a grid of length 5.
Use the Factory Pattern to create a series of object factories for each of the character types, and change the main method of Game.java to use these factories.