Skip to content

Latest commit

 

History

History
93 lines (62 loc) · 2.69 KB

readme.md

File metadata and controls

93 lines (62 loc) · 2.69 KB

S.Leschev Design Patterns (Swift 5+)

Google Engineering Level: L6+

🏆 Awards

Ranking #Dev: Global TOP 300 (Certificate)

Sergey Leschev

Languages: Swift, Shell, Database (T-SQL, PL/SQL, MySQL), Concurrency (Python3).

Algorithms: linked lists, binary search, hash table, queue/stack, dfs/bfs, sort, heap/hash, two pointers, sliding window, tree, greedy problems etc.

💡 Strategy

The strategy pattern is used to create an interchangeable family of algorithms from which the required process is chosen at run-time.

Example

struct TestSubject {
    let pupilDiameter: Double
    let blushResponse: Double
    let isOrganic: Bool
}

protocol RealnessTesting: AnyObject {
    func testRealness(_ testSubject: TestSubject) -> Bool
}

final class VoightKampffTest: RealnessTesting {
    func testRealness(_ testSubject: TestSubject) -> Bool {
        return testSubject.pupilDiameter < 30.0 || testSubject.blushResponse == 0.0
    }
}

final class GeneticTest: RealnessTesting {
    func testRealness(_ testSubject: TestSubject) -> Bool {
        return testSubject.isOrganic
    }
}

final class BladeRunner {
    private let strategy: RealnessTesting

    init(test: RealnessTesting) {
        self.strategy = test
    }

    func testIfAndroid(_ testSubject: TestSubject) -> Bool {
        return !strategy.testRealness(testSubject)
    }
}

Usage

let rachel = TestSubject(pupilDiameter: 30.2,
                         blushResponse: 0.3,
                         isOrganic: false)

// Deckard is using a traditional test
let deckard = BladeRunner(test: VoightKampffTest())
let isRachelAndroid = deckard.testIfAndroid(rachel)

// Gaff is using a very precise method
let gaff = BladeRunner(test: GeneticTest())
let isDeckardAndroid = gaff.testIfAndroid(rachel)

Contacts

I have a clear focus on time-to-market and don't prioritize technical debt.

🛩️ #startups #management #cto #swift #typescript #database

📧 Email: sergey.leschev@gmail.com

👋 LinkedIn: https://linkedin.com/in/sergeyleschev

👋 Twitter: https://twitter.com/sergeyleschev

👋 Github: https://github.com/sergeyleschev

🌎 Website: https://sergeyleschev.github.io

🖨️ PDF: Download

ALT: SIARHEI LIASHCHOU