Created
October 25, 2010 15:34
-
-
Save samnang/645139 to your computer and use it in GitHub Desktop.
Implement Abstract Factory
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 MySqlDatabaseFactory | |
class << self | |
def create_connection | |
MySqlConnection.new | |
end | |
def create_generator | |
MySqlGenerator.new | |
end | |
end | |
end | |
class MySqlConnection | |
def initialize | |
puts "Setup mysql connection" | |
end | |
def open_connection | |
puts "Open mysql connection" | |
end | |
end | |
class MySqlGenerator | |
def create_table | |
puts "Create mysql table" | |
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
def load_adapter_from_config_file | |
MySqlDatabaseFactory #returning stub | |
end | |
adapter = load_adapter_from_config_file | |
adapter.create_connection.open_connection | |
adapter.create_generator.create_table |
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 SqliteDatabaseFactory | |
class << self | |
def create_connection | |
SqliteConnection.new | |
end | |
def create_generator | |
SqliteGenerator.new | |
end | |
end | |
end | |
class SqliteConnection | |
def initialize | |
puts "Setup sqlite connection" | |
end | |
def open_connection | |
puts "Open sqlite connection" | |
end | |
end | |
class SqliteGenerator | |
def create_table | |
puts "Create sqlite table" | |
end | |
#... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment