Created
October 13, 2013 20:42
-
-
Save Olefine/6967206 to your computer and use it in GitHub Desktop.
This file contains 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 "interface" | |
Strategy = interface { | |
required_methods :use | |
} | |
class StrategyOne | |
implements Strategy | |
def use | |
puts "This is first case" | |
end | |
end | |
class StrategyTwo | |
implements Strategy | |
def use | |
puts "This is second case" | |
end | |
end | |
class Contex | |
attr_accessor :strategy | |
def initialize(strategy) | |
@strategy = strategy | |
end | |
def get_case | |
@strategy.use | |
end | |
end | |
contex = Contex.new(StrategyOne.new) | |
contex.get_case |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment