Skip to content

Instantly share code, notes, and snippets.

@nooglersoon
Created June 9, 2020 00:37
Show Gist options
  • Save nooglersoon/8b7fc8d9f5dcc6c3906c28afb46e9b75 to your computer and use it in GitHub Desktop.
Save nooglersoon/8b7fc8d9f5dcc6c3906c28afb46e9b75 to your computer and use it in GitHub Desktop.
Medium Session: Introduction to Swift's OOP in Indonesia - Part 2D
/*
Menambahkan methods baru dari class Mobil, yaitu playEntertainment. Dengan parameternya adalah musicPlayer.
*/
class Mobil {
func playEntertainment (_ musicPlayer: Bool) -> String {
if musicPlayer {
return "The audio is now playing!"
}else{
return "You are not yet play the audio"
}
}
}
/*
Pada sub class dari mobil, Sedan memiliki methods baru yaitu playEntertainment. Namun dengan menambahkan dvdPlayer di dalamnya.
Tidak hanya parameter, namun isi dari method pun berubah
*/
class Sedan: Mobil { // -> Class Toyota merupakan subclass atau child class, sementara Mobil adalah superclass atau parent class
// Melakukan overload methods pada playEntertainment, menambahkan paramater baru dan merubah isi nya
func playEntertainment(_ dvdPlayer: Bool, _ musicPlayer: Bool) -> String {
if dvdPlayer || musicPlayer {
return "Your just enjoy a-half of your car entertainment"
}
else if dvdPlayer && musicPlayer {
return "Congratulations! You enjoy your full car entertainment"
} else {
return "You have not turn any entertainment yet!"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment