What is polymorphism?
Polymorphism is the ability of an object to take on many forms
let's say this is our main function
and we created our IUser class
IUser is an abstract class and it's important
and we have another class which implemented from IUser class
so when we are trying to create an object and use this object with many forms we use
thx for reading
Gauloran <3
Polymorphism is the ability of an object to take on many forms
let's say this is our main function
Kod:
void main(List<String> args) {
IUser user =
Turk(); //!Turk sınıfından bir nesne oluşturduk ve bunun türü IUser çünkü Turk sınıfı IUser sınıfından implemente edilmiş zaten işte bu polimorfizm diyebiliriz
user.sayName();
user =
English(); //!user nesnesine English sınıfından bir nesne yerleştirdik yapabiliriz bunu çünkü English sınıfı da IUser sınıfından implemente edilmiş
user.sayName();
}
and we created our IUser class
Kod:
abstract class IUser {
final String name;
IUser(this.name);
void sayName();
}
IUser is an abstract class and it's important
Kod:
class Turk implements IUser {
@override
String get name => "ali";
@override
void sayName() {
print("merhaba hoşgeldin $name");
}
}
and we have another class which implemented from IUser class
Kod:
class English implements IUser {
@override
String get name => "john";
@override
void sayName() {
print("welcome to your home $name");
}
}
so when we are trying to create an object and use this object with many forms we use
Kod:
IUser user = Turk(); //!Turk sınıfından bir nesne oluşturduk ve bunun türü IUser çünkü Turk sınıfı IUser sınıfından implemente edilmiş zaten işte bu polimorfizm diyebiliriz
user.sayName();
user = English(); //!user nesnesine English sınıfından bir nesne yerleştirdik yapabiliriz bunu çünkü English sınıfı da IUser sınıfından implemente edilmiş
user.sayName();
thx for reading
Gauloran <3