diff --git a/examples/structural/adapter.cpp b/examples/structural/adapter.cpp index ffc847c..0f59590 100644 --- a/examples/structural/adapter.cpp +++ b/examples/structural/adapter.cpp @@ -37,7 +37,6 @@ class Hunter class WildDog { public: - typedef std::shared_ptr ptr_t; void bark(void) { std::cout << "*wild dog bark*" << std::endl; @@ -47,7 +46,7 @@ class WildDog class WildDogAdapter : public Lion { public: - WildDogAdapter(WildDog::ptr_t dog) + WildDogAdapter(std::shared_ptr dog) : dog_(dog) { } @@ -58,12 +57,12 @@ class WildDogAdapter : public Lion } private: - WildDog::ptr_t dog_; + std::shared_ptr dog_; }; int main() { - WildDog::ptr_t wildDog = std::make_shared(); + std::shared_ptr wildDog = std::make_shared(); WildDogAdapter wildDogAdapter(wildDog); Hunter hunter; diff --git a/examples/structural/bridge.cpp b/examples/structural/bridge.cpp index b01dc15..024c38d 100644 --- a/examples/structural/bridge.cpp +++ b/examples/structural/bridge.cpp @@ -5,7 +5,6 @@ class Theme { public: - typedef std::shared_ptr ptr_t; virtual std::string getColor(void) = 0; }; @@ -18,7 +17,7 @@ class WebPage class About : public WebPage { public: - About(Theme::ptr_t theme) + About(std::shared_ptr theme) : theme_(theme) { } @@ -29,13 +28,13 @@ class About : public WebPage } private: - Theme::ptr_t theme_; + std::shared_ptr theme_; }; class Projects : public WebPage { public: - Projects(Theme::ptr_t theme) + Projects(std::shared_ptr theme) : theme_(theme) { } @@ -46,14 +45,14 @@ class Projects : public WebPage } private: - Theme::ptr_t theme_; + std::shared_ptr theme_; }; class Careers : public WebPage { public: - Careers(Theme::ptr_t theme) + Careers(std::shared_ptr theme) : theme_(theme) { } @@ -64,7 +63,7 @@ class Careers : public WebPage } private: - Theme::ptr_t theme_; + std::shared_ptr theme_; }; class DarkTheme : public Theme @@ -96,7 +95,7 @@ class AquaTheme : public Theme int main() { - Theme::ptr_t darkTheme = std::make_shared(); + std::shared_ptr darkTheme = std::make_shared(); About about(darkTheme); Careers careers(darkTheme); diff --git a/examples/structural/composite.cpp b/examples/structural/composite.cpp index c9db826..36c0370 100644 --- a/examples/structural/composite.cpp +++ b/examples/structural/composite.cpp @@ -6,7 +6,6 @@ class Employee { public: - typedef std::shared_ptr ptr_t; virtual std::string getName(void) = 0; virtual void setSalary(float salary) = 0; virtual float getSalary(void) = 0; @@ -84,7 +83,7 @@ class Designer : public Employee class Organization { public: - void addEmployee(Employee::ptr_t employee) + void addEmployee(std::shared_ptr employee) { employees_.push_back(employee); } @@ -100,14 +99,14 @@ class Organization } private: - std::vector employees_; + std::vector> employees_; }; int main() { // Prepare the employees. - Employee::ptr_t jane = std::make_shared("Jane Doe", 50000); - Employee::ptr_t john = std::make_shared("John Doe", 45000); + std::shared_ptr jane = std::make_shared("Jane", 50000); + std::shared_ptr john = std::make_shared("John", 45000); // Add them to the organization. Organization org; diff --git a/examples/structural/decorator.cpp b/examples/structural/decorator.cpp index 68f5074..b3cfcd4 100644 --- a/examples/structural/decorator.cpp +++ b/examples/structural/decorator.cpp @@ -5,7 +5,6 @@ class Coffee { public: - typedef std::shared_ptr ptr_t; virtual float getPrice(void) = 0; virtual std::string getDescription(void) = 0; }; @@ -27,7 +26,7 @@ class SimpleCoffee : public Coffee class MilkCoffee : public Coffee { public: - MilkCoffee(Coffee::ptr_t coffee) + MilkCoffee(std::shared_ptr coffee) : coffee_(coffee) { } @@ -43,13 +42,13 @@ class MilkCoffee : public Coffee } private: - Coffee::ptr_t coffee_; + std::shared_ptr coffee_; }; class WhipCoffee : public Coffee { public: - WhipCoffee(Coffee::ptr_t coffee) + WhipCoffee(std::shared_ptr coffee) : coffee_(coffee) { } @@ -65,13 +64,13 @@ class WhipCoffee : public Coffee } private: - Coffee::ptr_t coffee_; + std::shared_ptr coffee_; }; class VanillaCoffee : public Coffee { public: - VanillaCoffee(Coffee::ptr_t coffee) + VanillaCoffee(std::shared_ptr coffee) : coffee_(coffee) { } @@ -87,30 +86,30 @@ class VanillaCoffee : public Coffee } private: - Coffee::ptr_t coffee_; + std::shared_ptr coffee_; }; int main() { - Coffee::ptr_t simple = std::make_shared(); + std::shared_ptr simple = std::make_shared(); // Output: 3 std::cout << simple->getPrice() << std::endl; // Output: Simple coffee std::cout << simple->getDescription() << std::endl; - Coffee::ptr_t milk = std::make_shared(simple); + std::shared_ptr milk = std::make_shared(simple); // Output: 3.5 std::cout << milk->getPrice() << std::endl; // Output: Simple coffee, milk std::cout << milk->getDescription() << std::endl; - Coffee::ptr_t whip = std::make_shared(milk); + std::shared_ptr whip = std::make_shared(milk); // Output: 5.5 std::cout << whip->getPrice() << std::endl; // Output: Simple coffee, milk, whip std::cout << whip->getDescription() << std::endl; - Coffee::ptr_t vanilla = std::make_shared(whip); + std::shared_ptr vanilla = std::make_shared(whip); // Output: 6.5 std::cout << vanilla->getPrice() << std::endl; // Output: Simple coffee, milk, whip, vanilla diff --git a/examples/structural/facade.cpp b/examples/structural/facade.cpp index afd07d2..dfc8596 100644 --- a/examples/structural/facade.cpp +++ b/examples/structural/facade.cpp @@ -4,8 +4,6 @@ class Computer { public: - typedef std::shared_ptr ptr_t; - void makeBootSound(void) { std::cout << "Beep!" << std::endl; @@ -34,7 +32,7 @@ class Computer class ComputerFacade { public: - ComputerFacade(Computer::ptr_t computer) + ComputerFacade(std::shared_ptr computer) : computer_(computer) { } @@ -53,12 +51,12 @@ class ComputerFacade } private: - Computer::ptr_t computer_; + std::shared_ptr computer_; }; int main() { - Computer::ptr_t computer = std::make_shared(); + std::shared_ptr computer = std::make_shared(); ComputerFacade facade(computer); // Output: diff --git a/examples/structural/flyweight.cpp b/examples/structural/flyweight.cpp index aa4cc73..32953f4 100644 --- a/examples/structural/flyweight.cpp +++ b/examples/structural/flyweight.cpp @@ -2,18 +2,14 @@ #include #include -class Tea +struct Tea { - public: - typedef std::shared_ptr ptr_t; }; class TeaMaker { public: - typedef std::shared_ptr ptr_t; - - Tea::ptr_t make(const std::string& preference) + std::shared_ptr make(const std::string& preference) { auto match = availableTea_.find(preference); if (match == availableTea_.end()) { @@ -29,13 +25,13 @@ class TeaMaker } private: - std::unordered_map availableTea_; + std::unordered_map> availableTea_; }; class TeaShop { public: - TeaShop(TeaMaker::ptr_t maker) + TeaShop(std::shared_ptr maker) : maker_(maker) { } @@ -58,13 +54,13 @@ class TeaShop } private: - TeaMaker::ptr_t maker_; - std::unordered_map orders_; + std::shared_ptr maker_; + std::unordered_map> orders_; }; int main() { - TeaMaker::ptr_t maker = std::make_shared(); + std::shared_ptr maker = std::make_shared(); TeaShop shop(maker); // No orders have been taken, so there are no available teas. diff --git a/examples/structural/proxy.cpp b/examples/structural/proxy.cpp index 4db31a3..2ecf1d5 100644 --- a/examples/structural/proxy.cpp +++ b/examples/structural/proxy.cpp @@ -5,7 +5,6 @@ class Door { public: - typedef std::shared_ptr ptr_t; virtual void open(void) = 0; virtual void close(void) = 0; }; @@ -27,7 +26,7 @@ class LabDoor : public Door class SecuredDoor { public: - SecuredDoor(Door::ptr_t door) + SecuredDoor(std::shared_ptr door) : door_(door) { } @@ -52,12 +51,12 @@ class SecuredDoor return password == "Bond007"; } - Door::ptr_t door_; + std::shared_ptr door_; }; int main() { - Door::ptr_t labDoor = std::make_shared(); + std::shared_ptr labDoor = std::make_shared(); SecuredDoor securedDoor(labDoor); securedDoor.open("invalid"); // Output: No way, Jose!