Last active
March 3, 2022 16:21
-
-
Save arsalankhan994/33fcaec1668a7c8357e191103a137933 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
fun main() { | |
/* | |
Without Extension Functions | |
if we are using a class "SomeThirdPartyClass" and | |
we want to add one more function, then | |
we need to inherit the "SomeThirdPartyClass" class with | |
"MyClass" and write that function inside it and | |
use "MyClass" everywhere instead of "SomeThirdPartyClass" class | |
*/ | |
// Using third-party class and its functionality | |
val someThirdPartyClass = SomeThirdPartyClass() | |
someThirdPartyClass.firstFunctionality() | |
someThirdPartyClass.secondFunctionality() | |
// Need to add one more method, but we can't as it is a third-party class, | |
// so we need to inherit that class my own class | |
val myClass = MyClass() | |
myClass.firstFunctionality() | |
myClass.secondFunctionality() | |
myClass.thirdFunctionality() | |
} | |
open class SomeThirdPartyClass { | |
open fun firstFunctionality() {} | |
fun secondFunctionality() {} | |
} | |
class MyClass: SomeThirdPartyClass() { | |
fun thirdFunctionality() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment