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 PizzaFactory | |
| def create_pizza( type ) | |
| case type | |
| when :ham_mushroom | |
| HamMushroomPizza.new | |
| when :deluxe | |
| DeluxePizza.new | |
| when :hawaiian | |
| HawaiianPizza.new | |
| else |
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 Base | |
| def self.mysql_connector(config) | |
| #... | |
| end | |
| def self.oracle_connector(config) | |
| #... | |
| end | |
| end |
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 PizzaFactory { | |
| public enum PizzaType { | |
| HamMushroom, | |
| Deluxe, | |
| Hawaiian | |
| } | |
| public static Pizza createPizza(PizzaType pizzaType) { | |
| switch (pizzaType) { |
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 Currency < ActiveRecord::Base | |
| end | |
| class CurrencyObserver < ActiveRecord::Observer | |
| observe :currency | |
| def after_update(currency) | |
| puts "new rate for #{currency.symbol} : #{currency.rate}" | |
| end | |
| end |
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
| require "observer" | |
| class Currency | |
| include Observable | |
| def initialize(symbol,rate) | |
| @rate = rate | |
| @symbol = symbol | |
| end |
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
| #test | |
| class Logger | |
| def warning( msg ) | |
| #... | |
| end | |
| end | |
| #production | |
| class SingletonLogger < Logger | |
| include Singleton |
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 Logger | |
| include Singleton | |
| def warning( msg ) | |
| #... | |
| end | |
| end | |
| a = Logger.instance |
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
| function ss { | |
| if [ -e script/rails ]; then | |
| script/rails server $@ | |
| else | |
| script/server $@ | |
| fi | |
| } | |
| function sc { | |
| if [ -e script/rails ]; then | |
| script/rails console $@ |
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 Poker | |
| def initialize(game) | |
| @game = game | |
| end | |
| def evaluate_cards | |
| #... | |
| @game.primitive_operation | |
| #... | |
| end |
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 Poker | |
| def evaluate_cards | |
| primitive_operation1 | |
| primitive_operation2 | |
| end | |
| def primitive_operation1 | |
| raise "template method called!" | |
| end |