Last active
July 30, 2019 11:11
-
-
Save biloshkurskyi-ss/6d036d4f25fa29cd8e31750c4b9d014b to your computer and use it in GitHub Desktop.
OOP at Swift - Encapsulation
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
import Foundation | |
class Vehicle { | |
var model: String | |
var make: Int | |
init(model: String, make: Int) { | |
self.model = model | |
self.make = make | |
} | |
func start() { print("Vehicle - Start") } | |
func stop() { print("Vehicle - Stop") } | |
} | |
let сuriosity = Vehicle(model: "Rover", make: 2011) | |
class Car: Vehicle { | |
var tireCount: Int | |
private var isEngineWorks = false | |
init(model: String, make: Int, tireCount: Int = 4) { | |
self.tireCount = tireCount | |
super.init(model: model, make: make) | |
} | |
override func start() { | |
print("Car - Start") | |
} | |
override func stop() { | |
super.stop() | |
} | |
private func startEngine() { | |
isEngineWorks = true | |
} | |
private func stopEngine() { | |
isEngineWorks = false | |
} | |
} | |
let ford = Car(model: "Ford", make: 2018) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment