Added class hierarchies.
This commit is contained in:
		
							
								
								
									
										8
									
								
								double-dispatch/src/main/java/com/iluwatar/Asteroid.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								double-dispatch/src/main/java/com/iluwatar/Asteroid.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| package com.iluwatar; | ||||
|  | ||||
| public class Asteroid extends Meteoroid { | ||||
|  | ||||
| 	public Asteroid(int left, int top, int right, int bottom) { | ||||
| 		super(left, top, right, bottom); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										13
									
								
								double-dispatch/src/main/java/com/iluwatar/GameObject.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								double-dispatch/src/main/java/com/iluwatar/GameObject.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| package com.iluwatar; | ||||
|  | ||||
| public abstract class GameObject extends Rectangle { | ||||
| 	 | ||||
| 	public GameObject(int left, int top, int right, int bottom) { | ||||
| 		super(left, top, right, bottom); | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| 	public String toString() { | ||||
| 		return this.getClass().getSimpleName(); | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| package com.iluwatar; | ||||
|  | ||||
| public class Meteoroid extends GameObject { | ||||
|  | ||||
| 	public Meteoroid(int left, int top, int right, int bottom) { | ||||
| 		super(left, top, right, bottom); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										33
									
								
								double-dispatch/src/main/java/com/iluwatar/Rectangle.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								double-dispatch/src/main/java/com/iluwatar/Rectangle.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| package com.iluwatar; | ||||
|  | ||||
| public class Rectangle { | ||||
|  | ||||
| 	private int left; | ||||
| 	private int top; | ||||
| 	private int right; | ||||
| 	private int bottom; | ||||
|  | ||||
| 	public Rectangle(int left, int top, int right, int bottom) { | ||||
| 		this.left = left; | ||||
| 		this.top = top; | ||||
| 		this.right = right; | ||||
| 		this.bottom = bottom; | ||||
| 	} | ||||
| 	 | ||||
| 	public int getLeft() { | ||||
| 		return left; | ||||
| 	} | ||||
| 	public int getTop() { | ||||
| 		return top; | ||||
| 	} | ||||
| 	public int getRight() { | ||||
| 		return right; | ||||
| 	} | ||||
| 	public int getBottom() { | ||||
| 		return bottom; | ||||
| 	}	 | ||||
| 	 | ||||
| 	boolean intersectsWith(Rectangle r) { | ||||
| 		return !(r.getLeft() > getRight() || r.getRight() < getLeft() || r.getTop() > getBottom() || r.getBottom() < getTop()); | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| package com.iluwatar; | ||||
|  | ||||
| public class SpaceStationIss extends SpaceStationMir { | ||||
|  | ||||
| 	public SpaceStationIss(int left, int top, int right, int bottom) { | ||||
| 		super(left, top, right, bottom); | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| package com.iluwatar; | ||||
|  | ||||
| public class SpaceStationMir extends GameObject { | ||||
|  | ||||
| 	public SpaceStationMir(int left, int top, int right, int bottom) { | ||||
| 		super(left, top, right, bottom); | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user