Last active
June 11, 2023 08:50
-
-
Save sahinkaradeniz/129e5bc539b77e04dff192fc3605997b 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 Database { | |
fun fetchData(): String | |
} | |
class LocalDatabase : Database { | |
override fun fetchData(): String { | |
// Yerel veritabanından veri çekme işlemleri | |
return "local data" | |
} | |
} | |
class RemoteDatabase : Database { | |
override fun fetchData(): String { | |
// Uzak sunucudan veri çekme işlemleri | |
return "remote data" | |
} | |
} | |
interface DatabaseFactory { | |
fun createDatabase(): Database | |
} | |
class LocalDatabaseFactory : DatabaseFactory { | |
override fun createDatabase(): Database { | |
return LocalDatabase() | |
} | |
} | |
class RemoteDatabaseFactory : DatabaseFactory { | |
override fun createDatabase(): Database { | |
return RemoteDatabase() | |
} | |
} | |
// Kullanım | |
val isLocalDatabase = true // Veya dinamik olarak belirlenebilir | |
val databaseFactory: DatabaseFactory = if (isLocalDatabase) { | |
LocalDatabaseFactory() | |
} else { | |
RemoteDatabaseFactory() | |
} | |
val database = databaseFactory.createDatabase() | |
val data = database.fetchData() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment