Skip to content

Commit 01f23e2

Browse files
author
jason_yao
committed
update
1 parent 48790d4 commit 01f23e2

225 files changed

Lines changed: 5297 additions & 5297 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
#ifndef _HFDP_CPP_ADAPTER_DUCK_HPP_
2-
#define _HFDP_CPP_ADAPTER_DUCK_HPP_
3-
4-
#include "Ducks.hpp"
5-
6-
namespace HeadFirstDesignPatterns {
7-
namespace Adapter {
8-
namespace Ducks {
9-
10-
class Duck {
11-
12-
public: virtual ~Duck() = 0 {
13-
}
14-
public: virtual void fly() const = 0;
15-
public: virtual void quack() const = 0;
16-
};
17-
18-
} // namespace Ducks
19-
} // namespace Adapter
20-
} // namespace HeadFirstDesignPatterns
21-
22-
#endif
1+
#ifndef _HFDP_CPP_ADAPTER_DUCK_HPP_
2+
#define _HFDP_CPP_ADAPTER_DUCK_HPP_
3+
4+
#include "Ducks.hpp"
5+
6+
namespace HeadFirstDesignPatterns {
7+
namespace Adapter {
8+
namespace Ducks {
9+
10+
class Duck {
11+
12+
public: virtual ~Duck() {
13+
}
14+
public: virtual void fly() const = 0;
15+
public: virtual void quack() const = 0;
16+
};
17+
18+
} // namespace Ducks
19+
} // namespace Adapter
20+
} // namespace HeadFirstDesignPatterns
21+
22+
#endif
Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
#ifndef _HFDP_CPP_ADAPTER_DUCK_ADAPTER_HPP_
2-
#define _HFDP_CPP_ADAPTER_DUCK_ADAPTER_HPP_
3-
4-
#include "Ducks.hpp"
5-
#include <process.h>
6-
7-
namespace HeadFirstDesignPatterns {
8-
namespace Adapter {
9-
namespace Ducks {
10-
11-
class DuckAdapter : public Turkey {
12-
13-
private: std::auto_ptr< const Duck > _duck;
14-
private: int _random;
15-
16-
private: DuckAdapter( const DuckAdapter& ); // Disable copy constructor
17-
private: void operator=( const DuckAdapter& ); // Disable assignment operator
18-
19-
public: explicit DuckAdapter( const Duck* duck ) :
20-
_duck ( duck ) { assert( duck );
21-
srand( _getpid() );
22-
_random = rand() % 5;
23-
if( _random == 0 )
24-
_random = 1;
25-
}
26-
public: void fly() const { assert( _duck );
27-
for( int i = 0; i < _random; i++ ) {
28-
_duck->fly();
29-
}
30-
}
31-
public: void gobble() const { assert( _duck );
32-
_duck->quack();
33-
}
34-
};
35-
36-
} // namespace Ducks
37-
} // namespace Adapter
38-
} // namespace HeadFirstDesignPatterns
39-
40-
#endif
1+
#ifndef _HFDP_CPP_ADAPTER_DUCK_ADAPTER_HPP_
2+
#define _HFDP_CPP_ADAPTER_DUCK_ADAPTER_HPP_
3+
4+
#include "Ducks.hpp"
5+
#include <process.h>
6+
7+
namespace HeadFirstDesignPatterns {
8+
namespace Adapter {
9+
namespace Ducks {
10+
11+
class DuckAdapter : public Turkey {
12+
13+
private: std::auto_ptr< const Duck > _duck;
14+
private: int _random;
15+
16+
private: DuckAdapter( const DuckAdapter& ); // Disable copy constructor
17+
private: void operator=( const DuckAdapter& ); // Disable assignment operator
18+
19+
public: explicit DuckAdapter( const Duck* duck ) :
20+
_duck ( duck ) { assert( duck );
21+
srand( _getpid() );
22+
_random = rand() % 5;
23+
if( _random == 0 )
24+
_random = 1;
25+
}
26+
public: void fly() const { assert( _duck );
27+
for( int i = 0; i < _random; i++ ) {
28+
_duck->fly();
29+
}
30+
}
31+
public: void gobble() const { assert( _duck );
32+
_duck->quack();
33+
}
34+
};
35+
36+
} // namespace Ducks
37+
} // namespace Adapter
38+
} // namespace HeadFirstDesignPatterns
39+
40+
#endif
58 KB
Binary file not shown.
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#include "Ducks.hpp"
2-
3-
using namespace HeadFirstDesignPatterns::Adapter::Ducks;
4-
1+
include "Ducks.hpp"
2+
3+
using namespace HeadFirstDesignPatterns::Adapter::Ducks;
4+
55
void testDuck( const Duck* duck ) {
66
duck->quack();
77
duck->fly();
8-
}
9-
10-
int main( int argc, char* argv[] ) {
11-
8+
}
9+
10+
int main( int argc, char* argv[] ) {
11+
1212
std::auto_ptr< MallardDuck > duck( new MallardDuck() );
1313

1414
#ifdef _DUCK_ADAPTER_
@@ -18,21 +18,21 @@ int main( int argc, char* argv[] ) {
1818
std::cout << "The DuckAdapter says..." << std::endl;
1919
duckAdapter->gobble();
2020
duckAdapter->fly();
21-
}
22-
#else
21+
}
22+
#else
2323
std::auto_ptr< WildTurkey > turkey( new WildTurkey() );
2424
std::auto_ptr< Duck > turkeyAdapter( new TurkeyAdapter( turkey.get() ) );
25-
25+
2626
std::cout << "The Turkey says..." << std::endl;
2727
turkey->gobble();
28-
turkey->fly();
29-
28+
turkey->fly();
29+
3030
std::cout << std::endl << "The Duck says..." << std::endl;
31-
testDuck( duck.get() );
32-
31+
testDuck( duck.get() );
32+
3333
std::cout << std::endl << "The TurkeyAdapter says..." << std::endl;
34-
testDuck( turkeyAdapter.get() );
35-
#endif
36-
37-
return 0;
38-
}
34+
testDuck( turkeyAdapter.get() );
35+
#endif
36+
37+
return 0;
38+
}
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
#ifndef _HFDP_CPP_ADAPTER_BIRDS_HPP_
2-
#define _HFDP_CPP_ADAPTER_BIRDS_HPP_
3-
4-
#include "../../Standard.h"
5-
6-
#include "Duck.hpp"
7-
#include "MallardDuck.hpp"
8-
9-
#include "Turkey.hpp"
10-
#include "WildTurkey.hpp"
11-
#include "TurkeyAdapter.hpp"
12-
13-
//#define _DUCK_ADAPTER_
14-
#ifdef _DUCK_ADAPTER_
15-
#include "DuckAdapter.hpp"
16-
#endif
17-
18-
#endif
1+
#ifndef _HFDP_CPP_ADAPTER_BIRDS_HPP_
2+
#define _HFDP_CPP_ADAPTER_BIRDS_HPP_
3+
4+
#include "../../Standard.h"
5+
6+
#include "Duck.hpp"
7+
#include "MallardDuck.hpp"
8+
9+
#include "Turkey.hpp"
10+
#include "WildTurkey.hpp"
11+
#include "TurkeyAdapter.hpp"
12+
13+
//#define _DUCK_ADAPTER_
14+
#ifdef _DUCK_ADAPTER_
15+
#include "DuckAdapter.hpp"
16+
#endif
17+
18+
#endif
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
#ifndef _HFDP_CPP_ADAPTER_MALLARD_DUCK_HPP_
2-
#define _HFDP_CPP_ADAPTER_MALLARD_DUCK_HPP_
3-
4-
#include "Ducks.hpp"
5-
6-
namespace HeadFirstDesignPatterns {
7-
namespace Adapter {
8-
namespace Ducks {
9-
10-
class MallardDuck : public Duck {
11-
12-
public: void fly() const {
13-
std::cout << "I'm flying" << std::endl;
14-
}
15-
public: void quack() const {
16-
std::cout << "Quack" << std::endl;
17-
}
18-
};
19-
20-
} // namespace Ducks
21-
} // namespace Adapter
22-
} // namespace HeadFirstDesignPatterns
23-
24-
#endif
1+
#ifndef _HFDP_CPP_ADAPTER_MALLARD_DUCK_HPP_
2+
#define _HFDP_CPP_ADAPTER_MALLARD_DUCK_HPP_
3+
4+
#include "Ducks.hpp"
5+
6+
namespace HeadFirstDesignPatterns {
7+
namespace Adapter {
8+
namespace Ducks {
9+
10+
class MallardDuck : public Duck {
11+
12+
public: void fly() const {
13+
std::cout << "I'm flying" << std::endl;
14+
}
15+
public: void quack() const {
16+
std::cout << "Quack" << std::endl;
17+
}
18+
};
19+
20+
} // namespace Ducks
21+
} // namespace Adapter
22+
} // namespace HeadFirstDesignPatterns
23+
24+
#endif
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
#ifndef _HFDP_CPP_ADAPTER_TURKEY_HPP_
2-
#define _HFDP_CPP_ADAPTER_TURKEY_HPP_
3-
4-
#include "Ducks.hpp"
5-
6-
namespace HeadFirstDesignPatterns {
7-
namespace Adapter {
8-
namespace Ducks {
9-
10-
class Turkey {
11-
12-
public: virtual ~Turkey() = 0 {
13-
}
14-
public: virtual void gobble() const = 0;
15-
public: virtual void fly() const = 0;
16-
};
17-
18-
} // namespace Ducks
19-
} // namespace Adapter
20-
} // namespace HeadFirstDesignPatterns
21-
22-
#endif
1+
#ifndef _HFDP_CPP_ADAPTER_TURKEY_HPP_
2+
#define _HFDP_CPP_ADAPTER_TURKEY_HPP_
3+
4+
#include "Ducks.hpp"
5+
6+
namespace HeadFirstDesignPatterns {
7+
namespace Adapter {
8+
namespace Ducks {
9+
10+
class Turkey {
11+
12+
public: virtual ~Turkey() {
13+
}
14+
public: virtual void gobble() const = 0;
15+
public: virtual void fly() const = 0;
16+
};
17+
18+
} // namespace Ducks
19+
} // namespace Adapter
20+
} // namespace HeadFirstDesignPatterns
21+
22+
#endif
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
#ifndef _HFDP_CPP_ADAPTER_TURKEY_ADAPTER_HPP_
2-
#define _HFDP_CPP_ADAPTER_TURKEY_ADAPTER_HPP_
3-
4-
#include "Ducks.hpp"
5-
6-
namespace HeadFirstDesignPatterns {
7-
namespace Adapter {
8-
namespace Ducks {
9-
10-
class TurkeyAdapter : public Duck {
11-
12-
private: const Turkey* _turkey;
13-
14-
private: TurkeyAdapter( const TurkeyAdapter& ); // Disable copy constructor
15-
private: void operator=( const TurkeyAdapter& ); // Disable assignment operator
16-
17-
public: explicit TurkeyAdapter( const Turkey* turkey ) :
18-
_turkey( turkey ) { assert( turkey );
19-
}
20-
public: void fly() const { assert( _turkey );
21-
for( int i = 0; i < 5; i++ ) {
22-
_turkey->fly();
23-
}
24-
}
25-
public: void quack() const { assert( _turkey );
26-
_turkey->gobble();
27-
}
28-
};
29-
30-
} // namespace Ducks
31-
} // namespace Adapter
32-
} // namespace HeadFirstDesignPatterns
33-
34-
#endif
1+
#ifndef _HFDP_CPP_ADAPTER_TURKEY_ADAPTER_HPP_
2+
#define _HFDP_CPP_ADAPTER_TURKEY_ADAPTER_HPP_
3+
4+
#include "Ducks.hpp"
5+
6+
namespace HeadFirstDesignPatterns {
7+
namespace Adapter {
8+
namespace Ducks {
9+
10+
class TurkeyAdapter : public Duck {
11+
12+
private: const Turkey* _turkey;
13+
14+
private: TurkeyAdapter( const TurkeyAdapter& ); // Disable copy constructor
15+
private: void operator=( const TurkeyAdapter& ); // Disable assignment operator
16+
17+
public: explicit TurkeyAdapter( const Turkey* turkey ) :
18+
_turkey( turkey ) { assert( turkey );
19+
}
20+
public: void fly() const { assert( _turkey );
21+
for( int i = 0; i < 5; i++ ) {
22+
_turkey->fly();
23+
}
24+
}
25+
public: void quack() const { assert( _turkey );
26+
_turkey->gobble();
27+
}
28+
};
29+
30+
} // namespace Ducks
31+
} // namespace Adapter
32+
} // namespace HeadFirstDesignPatterns
33+
34+
#endif

0 commit comments

Comments
 (0)