Created
February 23, 2011 09:16
-
-
Save detsam/840208 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
interface DataSource { | |
public String getData(); | |
} | |
class RestDataSource implements DataSource { | |
... | |
} | |
class SqlDataSource implements DataSource { | |
... | |
} | |
class Parser { | |
private DataSource dataSource; | |
public Parser() { | |
} | |
public void setDataSource(DataSource dataSource) { | |
this.dataSource = dataSource; | |
} | |
public void parse() { | |
String source = dataSource.getData(); | |
doParse(source); | |
} | |
} | |
Parser parser = new Parser(); | |
parser.setDataSource(new RestDataSource("file://tmp/forparse.txt")); | |
parser.parse(); | |
parser.setDataSource(new SqlDataSource("mysql:user@localhost/db/schema/table/?=SELECT forparse FROM source")); | |
parser.parse(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment