随笔分类 - 设计模式
摘要:observer.h quack_observable.h duck.h observable.h mallard_duck.h redhead_duck.h duck_call.h rubber_duck.h countable_duck.h countable_duck.cpp ivector.
阅读全文
摘要:menu_component.h menu_item.h menu.h ivector.h main.cpp
阅读全文
摘要:iterator.h menu.h diner_menu.h pancake_house_menu.h main.cpp
阅读全文
摘要:iterator.h menu_item.h pancake_house_menu.h main.cpp
阅读全文
摘要:state.h gumball_machine.h 说明:这里之所有要把SoldOutState等状态定义在GumballMachine类之中是因为两者之间有相互的依赖,暂时没有想到其他的解决方法。 main.cpp
阅读全文
摘要:light.h popper.h facade.h main.cpp
阅读全文
摘要:duck.h mallard_duck.h turkey.h turkey_adapter.h main.cpp
阅读全文
摘要:先看如果不用命令模式的实现: light.h tv.h remote.h main.cpp 再看看使用命令模式的实现 light.h和tv.h不变 command.h light_on_command.h light_off_command.h tv_on_command.h tv_off_comm
阅读全文
摘要:Dough.h ThinCrustDough.h Sauce.h MarinaraSauce.h Pizza.h CheesePizza.h GreekPizza.h PizzaStore.h NYPizzaStore.h PizzaIngredientFactory.h NYPizzaIngred
阅读全文
摘要:引用原书的一句话:所有的工厂模式都用来封装对象的创建,工厂方法模式通过让子类决定该创建的对象是什么来达到封装的目的。 Pizza类及其派生类与上一例相同 PizzaStore.h NYPizzaStore.h ChiChagoPizzaStore.h main.cpp
阅读全文
摘要:为了引出后续的工厂方法,把在简单工厂模式的基础上增加了新功能——加盟店 简而言之就是把原来的单一简单工厂(能生产cheese和greek两种pizza)细分成了纽约地区的和芝加哥地区的(每种地区都能生产cheese和greek两种pizza) 和之前的简单工厂相比,PizzaStore中的Pizza
阅读全文
摘要:Pizza.h 1 #ifndef _PIZZA_H 2 #define _PIZZA_H 3 #include 4 #include 5 6 class Pizza 7 { 8 public: 9 Pizza(const std::string &type) : m_type(typ...
阅读全文
摘要:Beverage.h 1 #ifndef BEVERAGE_H_INCLUDED 2 #define BEVERAGE_H_INCLUDED 3 4 #include 5 6 class Beverage 7 { 8 public: 9 Beverage( std::string de...
阅读全文
摘要:WeatherData.h 1 #ifndef WEATHERDATA_H_INCLUDED 2 #define WEATHERDATA_H_INCLUDED 3 4 #include 5 #include "Display.h" 6 7 class WeatherData 8 { 9 pub...
阅读全文
摘要:前言最近在学习《Headfirst设计模式》,里面的例子都是Java的。但是我对Java并不熟悉,所以试着用C++来实现书中的例子。先来看看Duck以及子类Duck.h 1 #include 2 #include "FlyBehavior.h" 3 4 class Duck 5 { 6 priv...
阅读全文

浙公网安备 33010602011771号