Created
April 3, 2019 17:36
-
-
Save hitendradeveloper/0ec691dfa2ad2f97632e611870d1be59 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
// Hitendra Solanki | |
// Semi-singleton design pattern Playground example | |
//In semi-singleton design pattern, marking the class as final is optional | |
final class LogManager { | |
//shared object | |
static let logger: LogManager = LogManager(databaseURLEndpoint: "https://www.hitendrasolanki.com/logger/live") | |
private var databaseURLEndpoint: String | |
//not marked as private, anyone is allowed to access this initialiser outside of the class | |
init(databaseURLEndpoint: String) { | |
self.databaseURLEndpoint = databaseURLEndpoint | |
} | |
func log(_ value: String...){ | |
//complex code to connect to the databaseURLEndpoint and send the value to server directly | |
} | |
} | |
//This is function executes our main code | |
func main(){ | |
LogManager.logger.log("main log from medium blog on live server endpoint") //this will log on "/live" endpoint | |
} | |
// This is function executes our TEST MODE code | |
// Here in playground, Hitendra Solanki created this method for the demostratino purpose only | |
// Usually we write this kind of test codes, inside the test targe of the XCode-project | |
func testThatLogManger(){ | |
//we are allowed to create an instace of class LogManager, | |
//because it follows the Semi-Singleton design patterns | |
let logManagerTestObject = LogManager(databaseURLEndpoint: "https://www.hitendrasolanki.com/logger/test") | |
logManagerTestObject.log("test log from medium blog on test server endpoint") //this will log on "/test" endpoint | |
} | |
main() //call main | |
testThatLogManger() //call test execution | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment