From 040aedb6ce1144913ec70b3b707d0e479ba8616d Mon Sep 17 00:00:00 2001 From: Ian Dinwoodie Date: Sun, 19 May 2019 17:54:39 -0400 Subject: [PATCH] Updated output comment location for improved readability. Reading the output before reading the line that would result in such output seemed to interrupt the flow of reading. --- README.md | 41 +++++++++++++++----------- examples/creational/builder.cpp | 4 +-- examples/creational/simple_factory.cpp | 8 ++--- examples/structural/bridge.cpp | 4 +-- examples/structural/decorator.cpp | 16 +++++----- examples/structural/facade.cpp | 4 +-- examples/structural/flyweight.cpp | 5 ++++ 7 files changed, 46 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index a856a0a..4a680c5 100644 --- a/README.md +++ b/README.md @@ -155,18 +155,18 @@ Here is how this can be used: // Make a door with dimensions 100x200. std::shared_ptr door = DoorFactory::makeDoor(100, 200); -// Output: width = 100 std::cout << "width = " << door->getWidth() << std::endl; -// Output: height = 200 +// Output: width = 100 std::cout << "height = " << door->getHeight() << std::endl; +// Output: height = 200 // We can use the factory again to make a door with dimensions 50x100. std::shared_ptr door2 = DoorFactory::makeDoor(50, 100); -// Output: width = 50 std::cout << "width = " << door2->getWidth() << std::endl; -// Output: height = 100 +// Output: width = 50 std::cout << "height = " << door2->getHeight() << std::endl; +// Output: height = 100 ``` #### When To Use @@ -583,8 +583,8 @@ std::shared_ptr burger = BurgerBuilder(2). addLettuce(). addTomato(). build(); -// Output: 2 patties, pepperoni, lettuce, tomato burger->getDescription(); +// Output: 2 patties, pepperoni, lettuce, tomato // One triple patty buger with everything. std::shared_ptr burger2 = BurgerBuilder(3). @@ -593,8 +593,8 @@ std::shared_ptr burger2 = BurgerBuilder(3). addLettuce(). addTomato(). build(); -// Output: 3 patties, cheese, pepperoni, lettuce, tomato burger2->getDescription(); +// Output: 3 patties, cheese, pepperoni, lettuce, tomato ``` #### When To Use @@ -1029,10 +1029,10 @@ std::shared_ptr darkTheme = std::make_shared(); About about(darkTheme); Careers careers(darkTheme); -// Output: About page in dark palette std::cout << about.getContent() << std::endl; -// Output: Careers page in dark palette +// Output: About page in dark palette std::cout << careers.getContent() << std::endl; +// Output: Careers page in dark palette ``` #### When To Use @@ -1320,28 +1320,28 @@ Here is how this can be used: ```cpp std::shared_ptr simple = std::make_shared(); -// Output: 3 std::cout << simple->getPrice() << std::endl; -// Output: Simple coffee +// Output: 3 std::cout << simple->getDescription() << std::endl; +// Output: Simple coffee std::shared_ptr milk = std::make_shared(simple); -// Output: 3.5 std::cout << milk->getPrice() << std::endl; -// Output: Simple coffee, milk +// Output: 3.5 std::cout << milk->getDescription() << std::endl; +// Output: Simple coffee, milk std::shared_ptr whip = std::make_shared(milk); -// Output: 5.5 std::cout << whip->getPrice() << std::endl; -// Output: Simple coffee, milk, whip +// Output: 5.5 std::cout << whip->getDescription() << std::endl; +// Output: Simple coffee, milk, whip std::shared_ptr vanilla = std::make_shared(whip); -// Output: 6.5 std::cout << vanilla->getPrice() << std::endl; -// Output: Simple coffee, milk, whip, vanilla +// Output: 6.5 std::cout << vanilla->getDescription() << std::endl; +// Output: Simple coffee, milk, whip, vanilla ``` #### When To Use @@ -1437,16 +1437,16 @@ Here is how this can be used: std::shared_ptr computer = std::make_shared(); ComputerFacade facade(computer); +facade.turnOn(); // Output: // Beep! // Loading... // Ready to use! -facade.turnOn(); +facade.turnOff(); // Output: // Closing all programs! // Zzz -facade.turnOff(); ``` #### When To Use @@ -1568,6 +1568,11 @@ std::cout << shop.getPreferenceCount() << std::endl; // Output: 3 // Serve the customers. shop.serve(); +// Output: (Note: Since the map is unordered, the serving order may vary.) +// Serving tea to table 4 +// Serving tea to table 5 +// Serving tea to table 1 +// Serving tea to table 2 ``` #### When To Use diff --git a/examples/creational/builder.cpp b/examples/creational/builder.cpp index af6426c..9b15460 100644 --- a/examples/creational/builder.cpp +++ b/examples/creational/builder.cpp @@ -95,8 +95,8 @@ int main() addLettuce(). addTomato(). build(); - // Output: 2 patties, pepperoni, lettuce, tomato burger->getDescription(); + // Output: 2 patties, pepperoni, lettuce, tomato // One triple patty buger with everything. std::shared_ptr burger2 = BurgerBuilder(3). @@ -105,8 +105,8 @@ int main() addLettuce(). addTomato(). build(); - // Output: 3 patties, cheese, pepperoni, lettuce, tomato burger2->getDescription(); + // Output: 3 patties, cheese, pepperoni, lettuce, tomato return 0; } diff --git a/examples/creational/simple_factory.cpp b/examples/creational/simple_factory.cpp index 90134a7..7b57206 100644 --- a/examples/creational/simple_factory.cpp +++ b/examples/creational/simple_factory.cpp @@ -46,18 +46,18 @@ int main() // Make a door with dimensions 100x200. std::shared_ptr door = DoorFactory::makeDoor(100, 200); - // Output: width = 100 std::cout << "width = " << door->getWidth() << std::endl; - // Output: height = 200 + // Output: width = 100 std::cout << "height = " << door->getHeight() << std::endl; + // Output: height = 200 // We can use the factory again to make a door with dimensions 50x100. std::shared_ptr door2 = DoorFactory::makeDoor(50, 100); - // Output: width = 50 std::cout << "width = " << door2->getWidth() << std::endl; - // Output: height = 100 + // Output: width = 50 std::cout << "height = " << door2->getHeight() << std::endl; + // Output: height = 100 return 0; } diff --git a/examples/structural/bridge.cpp b/examples/structural/bridge.cpp index 024c38d..64c0095 100644 --- a/examples/structural/bridge.cpp +++ b/examples/structural/bridge.cpp @@ -99,10 +99,10 @@ int main() About about(darkTheme); Careers careers(darkTheme); - // Output: About page in dark palette std::cout << about.getContent() << std::endl; - // Output: Careers page in dark palette + // Output: About page in dark palette std::cout << careers.getContent() << std::endl; + // Output: Careers page in dark palette return 0; } diff --git a/examples/structural/decorator.cpp b/examples/structural/decorator.cpp index a51374f..7d0cbf8 100644 --- a/examples/structural/decorator.cpp +++ b/examples/structural/decorator.cpp @@ -92,28 +92,28 @@ class VanillaCoffee : public Coffee int main() { std::shared_ptr simple = std::make_shared(); - // Output: 3 std::cout << simple->getPrice() << std::endl; - // Output: Simple coffee + // Output: 3 std::cout << simple->getDescription() << std::endl; + // Output: Simple coffee std::shared_ptr milk = std::make_shared(simple); - // Output: 3.5 std::cout << milk->getPrice() << std::endl; - // Output: Simple coffee, milk + // Output: 3.5 std::cout << milk->getDescription() << std::endl; + // Output: Simple coffee, milk std::shared_ptr whip = std::make_shared(milk); - // Output: 5.5 std::cout << whip->getPrice() << std::endl; - // Output: Simple coffee, milk, whip + // Output: 5.5 std::cout << whip->getDescription() << std::endl; + // Output: Simple coffee, milk, whip std::shared_ptr vanilla = std::make_shared(whip); - // Output: 6.5 std::cout << vanilla->getPrice() << std::endl; - // Output: Simple coffee, milk, whip, vanilla + // Output: 6.5 std::cout << vanilla->getDescription() << std::endl; + // Output: Simple coffee, milk, whip, vanilla return 0; } diff --git a/examples/structural/facade.cpp b/examples/structural/facade.cpp index dfc8596..d1e4b6e 100644 --- a/examples/structural/facade.cpp +++ b/examples/structural/facade.cpp @@ -59,16 +59,16 @@ int main() std::shared_ptr computer = std::make_shared(); ComputerFacade facade(computer); + facade.turnOn(); // Output: // Beep! // Loading... // Ready to use! - facade.turnOn(); + facade.turnOff(); // Output: // Closing all programs! // Zzz - facade.turnOff(); return 0; } diff --git a/examples/structural/flyweight.cpp b/examples/structural/flyweight.cpp index 32953f4..56debb4 100644 --- a/examples/structural/flyweight.cpp +++ b/examples/structural/flyweight.cpp @@ -83,6 +83,11 @@ int main() // Serve the customers. shop.serve(); + // Output: (Note: Since the map is unordered, the serving order may vary.) + // Serving tea to table 4 + // Serving tea to table 5 + // Serving tea to table 1 + // Serving tea to table 2 return 0; }