This post is a sequel of previous How to start using Design Patterns post, describing the Memory Palace memorization method. I recommend you to read it before starting to read this post.
For example, I can use my sitting room as a basis for the remembering path. In this room I have the following objects:
Table, big bright window, lamp, sofa, picture on the wall, small bookcase, CD rack, telephone, television, DVD player, chair, mirror, black and white photographs, etc.
I want to put all the units required for remembering the StrategyContext implementation in that room. I’ll start from window and will move to the door out of the room.
When I hear the word “strategy”, the first image comes to my mind is an ancient roman warrior with armors. “Context” associates with Jacuzzi for me(something that surrounds you). So I “see” the roman warrior sitting in the Jacuzzi(pay attention at bubbles and moist air in the room).
Here is an example implementation of the GoF Strategy pattern, main concept of which we want to remember:
I’ve taken it at Strategy PHP example from software pattern catalog:
private $strategy = NULL;
//bookList is not instantiated at construct time
public function __construct($strategy_ind_id) {
switch ($strategy_ind_id) {
case “C”:
$this->strategy = new StrategyCaps();
break;
case “E”:
$this->strategy = new StrategyExclaim();
break;
case “S”:
$this->strategy = new StrategyStars();
break;
}
}
public function showBookTitle($book) {
return $this->strategy->showTitle($book);
}
}
interface StrategyInterface {
public function showTitle($book_in);
}
class StrategyCaps implements StrategyInterface {
public function showTitle($book_in) {
$title = $book_in->getTitle();
$this->titleCount++;
return strtoupper ($title);
}
}
class StrategyExclaim implements StrategyInterface {
public function showTitle($book_in) {
$title = $book_in->getTitle();
$this->titleCount++;
return Str_replace(‘ ‘,‘!’,$title);
}
}
class StrategyStars implements StrategyInterface {
public function showTitle($book_in) {
$title = $book_in->getTitle();
$this->titleCount++;
return Str_replace(‘ ‘,‘*’,$title);
}
}
class Book {
private $author;
private $title;
function __construct($title_in, $author_in) {
$this->author = $author_in;
$this->title = $title_in;
}
function getAuthor() {
return $this->author;
}
function getTitle() {
return $this->title;
}
function getAuthorAndTitle() {
return $this->getTitle() . ‘ by ‘ . $this->getAuthor();
}
}
$book = new Book(‘PHP for Cats’,‘Larry Truett’);
$strategyContextC = new StrategyContext(‘C’);
echo $strategyContextC->showBookTitle($book);
?>
After I see the robot made from LEGO constructor, which holds the E letter in its manipulator-hand at the picture at the wall.
After that I see the robot’s manipulator is getting out of picture and moves the letter E to the opposite corner of the room, while the roman warrior has got out of the Jacuzzi and moved to those part of room. Manipulator gives this E letter, and while it falls down to the warrior’s hands it transforms into the exclamation mark(assign the strategy property an StrategyExclamation implementation – $this->strategy = new StrategyExclaim())
Now let’s move to particular StrategyExclaim implementation:
I’ll use the kitchen for that class. I see the warrior standing near the table, holding the knife. He wants to cut the tasty cake in form of exclamation mark, lying on the table(StrategyExclaim).
Near the sink I the the ostsilograf with right sine function on them. At the end of room, I see the black “magic” curtains, like those in circus. And after that I see the top of the curtains lowering(опускаются), until we can see the book’s, standing behind the curtains, top part with its title(function showTitle($book));
Now, If I’ll walk this path I’ll can remind this pattern implementation. It is important, to now only remember every line of implementation, but more of core concepts(main parts), which will help you to remind the implementation.
Because remembering the source code is not a linear information, you’ll have to be creative and find the way of grouping the concepts and make a cross connections between them.
It is strongly recommended for you, to make your own “story”, because your own feelings and imagination images means much more to you, than other peoples perception, hence are remembered faster and stronger.
Our main purpose is not just in fast remembering the pattern, but in stay it with us for a quite long period of time. After first learning I reminisce the remembered information in my imagination, without looking at the paper or laptop
1) after 15 minutes
2) after an hour
3) after about 6 hours
4) on the next day
5) .. week
After that, if you want this information to stay in your long-term memory all you have to do is to reminisce this information on a monthly basis. It will be enough.
I’m using the technique to memorizing different types of information: UNIX shell commands, foreign language words, framework constructs, etc.
Tags: design patterns, GoF, memory palace, mnemonics, strategy pattern

