Skip to content

Instantly share code, notes, and snippets.

@arsalankhan994
Last active March 3, 2022 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arsalankhan994/33fcaec1668a7c8357e191103a137933 to your computer and use it in GitHub Desktop.
Save arsalankhan994/33fcaec1668a7c8357e191103a137933 to your computer and use it in GitHub Desktop.
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