This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Duck.h" | |
#include "QuackBehavior.h" | |
Duck::Duck(QuackBehavior * quackBehavior) { | |
howToQuack = quackBehavior; | |
} | |
Duck::~Duck() { | |
delete howToQuack; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DUCK_H_ | |
#define DUCK_H_ | |
class QuackBehavior; | |
class Duck { | |
public: | |
Duck(QuackBehavior * quackBehavior); | |
virtual ~Duck(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef QUACKBEHAVIOR_H_ | |
#define QUACKBEHAVIOR_H_ | |
class QuackBehavior { | |
public: | |
QuackBehavior(){}; | |
virtual ~QuackBehavior(){}; | |
virtual void quack() = 0; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Duck.h" | |
#include "QuackBehaviors/Quack.h" | |
#include "QuackBehaviors/Squeak.h" | |
#include "QuackBehaviors/MuteQuack.h" | |
int main(int argc, const char **argv) { | |
Duck duck(new Quack); | |
duck.quack(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef SQUEAK_H_ | |
#define SQUEAK_H_ | |
#include "../QuackBehavior.h" | |
class Squeak : public QuackBehavior { | |
public: | |
Squeak(); | |
virtual ~Squeak(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Squeak.h" | |
#include <iostream> | |
using namespace std; | |
Squeak::Squeak() {} | |
Squeak::~Squeak() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (just-quacking) | |
(printf "Quack!\n")) | |
(define (squeaking) | |
(printf "Squeak!\n")) | |
(define (mute-quacking) | |
(printf "<< Silence >>\n")) | |
(define (quack how-to-quack) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Duck | |
def initialize(how_to_quack) | |
@how_to_quack = how_to_quack | |
end | |
def how_to_quack=(how_to_quack) | |
@how_to_quack = how_to_quack | |
end | |
def quack |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package game; | |
public class Generation { | |
private LivingCells livingCells; | |
private Rules rules; | |
public Generation(LivingCells cells, Rules rules) { | |
this.livingCells = cells; | |
this.rules = rules; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package game; | |
public interface Rules { | |
public boolean shouldStayAlive(int numberOfNeighbors); | |
public boolean shouldBeBorn(int numberOfNeighbors); | |
} |
OlderNewer