PatternCraft - Adapter
Description:
The Adapter Design Pattern can be used, for example in the StarCraft game, to insert an external character in the game.
The pattern consists in having a wrapper class that will adapt the code from the external source.
Your Task
The adapter receives an instance of the object that it is going to adapt and handles it in a way that works with our application.
In this example we have the pre-loaded classes:
class Marine {
attack(target) {
target.health -= 6;
}
}
class Zealot {
attack(target) {
target.health -= 8;
}
}
class Zergling {
attack(target) {
target.health -= 5;
}
}
class Mario {
jumpAttack() {
console.log('Mamamia!');
return 3;
}
}
Complete the code so that we can create a MarioAdapter
that can attack as other units do.
Note to calculate how much damage mario
is going to do you have to call the jumpAttack
method (jump_attack
in Python).
Resources
PatternCraft series
- State Pattern
- Strategy Pattern
- Visitor Pattern
- Decorator Pattern
- Adapter Pattern
- Command Pattern
The original PatternCraft series (by John Lindquist) is a collection of Youtube videos that explains some of the design patterns and how they are used (or could be) on StarCraft.
Similar Kata:
Stats:
Created | Jan 9, 2016 |
Published | Jan 10, 2016 |
Warriors Trained | 5316 |
Total Skips | 118 |
Total Code Submissions | 15684 |
Total Times Completed | 4217 |
JavaScript Completions | 3635 |
C# Completions | 461 |
CoffeeScript Completions | 16 |
Python Completions | 161 |
Total Stars | 66 |
% of votes with a positive feedback rating | 85% of 264 |
Total "Very Satisfied" Votes | 204 |
Total "Somewhat Satisfied" Votes | 43 |
Total "Not Satisfied" Votes | 17 |