Created
June 9, 2020 00:37
-
-
Save nooglersoon/8b7fc8d9f5dcc6c3906c28afb46e9b75 to your computer and use it in GitHub Desktop.
Medium Session: Introduction to Swift's OOP in Indonesia - Part 2D
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
/* | |
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" | |
} | |
} | |
} |
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
/* | |
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