June 2018
Intermediate to advanced
310 pages
6h 32m
English
The game designer catches you in the evening, when you are about to go home of course. He wants to add the ammo count for the entire squad so each squad will be able to report how much ammo it has left:
fun bulletsLeft(): Long { // Do your job}
Where's the catch?
Well, you see, snipers have ammo as separate bullets:
class Bullet
Riflemen hold their bullets in magazines:
class Magazine(capacity: Int) { private val bullets = List(capacity) { Bullet() }}
Luckily, you don't have machine gunners on your squad yet, because they carry their ammo in belts...
So, you have a complex structure, which may or may not be nested. And you need to perform a certain operation on this structure as a whole. Here's where the Composite design ...
Read now
Unlock full access