# 2022-10-10 Fielder
## Object
- Try to hit the ball throwed by a pitcher.
- Input: `Batter`, `Pitch`
- Output: Result may be a `HitBall` (ground/fly) or a miss
- Field a ground/fly ball.
- Input: `Defender`, `HitBall`
- Output: `BattingResult` would be out, hit, homerun and miss.
## Behavior
1. `Pitcher` pitches
2. `Batter` hit the ball
- ground ball
- fly ball
- miss
3. `Fielder` try to handle the returned ball
- out
- hit
- homerun
## Architecture
Batter:
1. `Batter` inherits from `BaseballPlayer` and extends `hit` method
2. `hit` method takes `Pitch` as input and return `HitBall` (randomly decided)
Defender:
1. `Defender` inherits from `BaseballPlayer` and extends `field` method
2. `field` method takes `HitBall` as input and return `BattingResult` (randomly decided)
```mermaid
classDiagram
BaseballPlayer --|> Batter
BaseballPlayer --|> Defender
class BaseballPlayer {
String name
Int number
FieldPosition fieldPos
String getName()
Int getNumber()
FieldPosition getPos()
}
class Batter {
HitBall hit(Pitch pitch)
}
class Defender {
BattingResult field(HitBall ball)
}
class Pitch {
Grid pos
Grid position()
}
class HitBall {
int exitVelocity
int launchAngle
bool isGround()
bool isFly()
bool isMiss()
bool isHomerun()
}
class BattingResult {
hit = 0
hit_1base = 1
hit_2base = 2
hit_3base = 3
homerun = 4
ground_out = 5
fly_out = 6
strike_out = 7
}
```
## Implementation