mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-16 20:59:07 +00:00
Organized into packages.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.iluwatar.creature;
|
||||
|
||||
import com.iluwatar.property.Color;
|
||||
import com.iluwatar.property.Movement;
|
||||
import com.iluwatar.property.Size;
|
||||
|
||||
public abstract class AbstractCreature implements Creature {
|
||||
|
||||
private String name;
|
||||
private Size size;
|
||||
private Movement movement;
|
||||
private Color color;
|
||||
|
||||
public AbstractCreature(String name, Size size, Movement movement, Color color) {
|
||||
this.name = name;
|
||||
this.size = size;
|
||||
this.movement = movement;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s [size=%s, movement=%s, color=%s]", name, size, movement, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Movement getMovement() {
|
||||
return movement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.iluwatar.creature;
|
||||
|
||||
import com.iluwatar.property.Color;
|
||||
import com.iluwatar.property.Movement;
|
||||
import com.iluwatar.property.Size;
|
||||
|
||||
public interface Creature {
|
||||
|
||||
String getName();
|
||||
|
||||
Size getSize();
|
||||
|
||||
Movement getMovement();
|
||||
|
||||
Color getColor();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.iluwatar.creature;
|
||||
|
||||
import com.iluwatar.property.Color;
|
||||
import com.iluwatar.property.Movement;
|
||||
import com.iluwatar.property.Size;
|
||||
|
||||
public class Dragon extends AbstractCreature {
|
||||
|
||||
public Dragon() {
|
||||
super("Dragon", Size.LARGE, Movement.FLYING, Color.RED);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.iluwatar.creature;
|
||||
|
||||
import com.iluwatar.property.Color;
|
||||
import com.iluwatar.property.Movement;
|
||||
import com.iluwatar.property.Size;
|
||||
|
||||
public class Goblin extends AbstractCreature {
|
||||
|
||||
public Goblin() {
|
||||
super("Goblin", Size.SMALL, Movement.WALKING, Color.GREEN);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.iluwatar.creature;
|
||||
|
||||
import com.iluwatar.property.Color;
|
||||
import com.iluwatar.property.Movement;
|
||||
import com.iluwatar.property.Size;
|
||||
|
||||
public class KillerBee extends AbstractCreature {
|
||||
|
||||
public KillerBee() {
|
||||
super("KillerBee", Size.SMALL, Movement.FLYING, Color.LIGHT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.iluwatar.creature;
|
||||
|
||||
import com.iluwatar.property.Color;
|
||||
import com.iluwatar.property.Movement;
|
||||
import com.iluwatar.property.Size;
|
||||
|
||||
public class Octopus extends AbstractCreature {
|
||||
|
||||
public Octopus() {
|
||||
super("Octopus", Size.NORMAL, Movement.SWIMMING, Color.DARK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.iluwatar.creature;
|
||||
|
||||
import com.iluwatar.property.Color;
|
||||
import com.iluwatar.property.Movement;
|
||||
import com.iluwatar.property.Size;
|
||||
|
||||
public class Shark extends AbstractCreature {
|
||||
|
||||
public Shark() {
|
||||
super("Shark", Size.NORMAL, Movement.SWIMMING, Color.LIGHT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.iluwatar.creature;
|
||||
|
||||
import com.iluwatar.property.Color;
|
||||
import com.iluwatar.property.Movement;
|
||||
import com.iluwatar.property.Size;
|
||||
|
||||
public class Troll extends AbstractCreature {
|
||||
|
||||
public Troll() {
|
||||
super("Troll", Size.LARGE, Movement.WALKING, Color.DARK);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user