R: data clump -> deltaX, deltaY -> Vector
This commit is contained in:
parent
bc7f93c387
commit
37b23abbd4
3 changed files with 21 additions and 8 deletions
11
TECHDEBT.md
11
TECHDEBT.md
|
|
@ -1,11 +1,18 @@
|
|||
# TODO
|
||||
|
||||
# RPP
|
||||
- [ ] Refine Abstractions
|
||||
- [ ] long parameter list
|
||||
- [ ] data clump
|
||||
- [ ] primitive obsession
|
||||
- [ ] middle man
|
||||
|
||||
# Mikado
|
||||
- [x] Remove deltaX, deltaY in Heading
|
||||
- [x] NORTH, etc -> Vector(0, 1)
|
||||
- [x] move -> return Pair but using vector
|
||||
- [x] Add Vector to enum class Heading
|
||||
- [x] Create Vector data class
|
||||
|
||||
# RPP
|
||||
- [ ] Design Patterns
|
||||
- [ ] SOLID++
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package org.example
|
||||
|
||||
enum class Heading(val symbol: Char, val deltaX: Int, val deltaY: Int) {
|
||||
NORTH('N', 0, 1),
|
||||
EAST('E', 1, 0),
|
||||
SOUTH('S', 0, -1),
|
||||
WEST('W', -1, 0),
|
||||
enum class Heading(val symbol: Char, val vector: Vector) {
|
||||
NORTH('N', Vector(0, 1)),
|
||||
EAST('E', Vector(1, 0)),
|
||||
SOUTH('S', Vector(0, -1)),
|
||||
WEST('W', Vector(-1, 0)),
|
||||
;
|
||||
|
||||
fun turnLeft(): Heading =
|
||||
|
|
@ -26,7 +26,7 @@ enum class Heading(val symbol: Char, val deltaX: Int, val deltaY: Int) {
|
|||
fun move(
|
||||
x: Int,
|
||||
y: Int,
|
||||
): Pair<Int, Int> = Pair(x + deltaX, y + deltaY)
|
||||
): Pair<Int, Int> = Pair(x + vector.deltaX, y + vector.deltaY)
|
||||
|
||||
override fun toString(): String = symbol.toString()
|
||||
|
||||
|
|
|
|||
6
src/main/kotlin/org/example/Vector.kt
Normal file
6
src/main/kotlin/org/example/Vector.kt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package org.example
|
||||
|
||||
data class Vector(
|
||||
val deltaX: Int,
|
||||
val deltaY: Int,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue