Definition of Abstraction:
Abstraction is the process of hiding the implementation
details and showing only the functionality to the user.
If the matter can be said a little more clearly. For example:
Abstraction A method that hides the internal objects and shows
the external objects to the user is called Abstraction.
Abstraction is useful when you want to define methods for generic
classes. For example if there are multiple classes, and they are
using the same method. In this case you can use Abstraction method.
Abstraction এর সংজ্ঞা :
Abstraction হল Implementation এর details গোপন করার এবং ব্যবহারকারীকে
শুধুমাত্র ফাঙ্কশনালিটি দেখানোর প্রক্রিয়া।
বিষয়টা যদি আরেকটু ক্লিয়ার করে বলা যায়। যেমনঃ
Abstraction এমন একটি পদ্ধতি যেটি ইউজারকে অভ্যন্তরীণ জিনিসগুলোকে hide রেখে
বাহিরের জিনিসগুলো ইউজারকে দেখানোকে Abstraction বলে।
আপনি যখন সাধারণ ক্লাসের জন্য পদ্ধতি সংজ্ঞায়িত করতে চান তখন Abstraction দরকারী।
উদাহরণস্বরূপ যদি একাধিক ক্লাস আছে, এবং তারা একই পদ্ধতি ব্যবহার করছে।
এক্ষেত্রে আপনি Abstraction পদ্ধতি ব্যবহার করতে পারেন।
protocol MyInterface {
func myMethod() -> String
}
extension MyInterface {
func myMethod() -> String {
fatalError("Not Implemented")
}
}
class MyConcreteClass: MyInterface {
func myMethod() -> String {
return "I'm a good boy."
}
}
print(MyConcreteClass().myMethod())
class MessageUser {
public func sendAMessage() -> String {
return ""
}
}
class Murad: MessageUser {
public override func sendAMessage() -> String {
return "Hi!, I'm Murad."
}
}
class Fahim: MessageUser {
public override func sendAMessage() -> String {
return "Hi!, He is Fahim."
}
}
let murad = Murad()
let fahim = Fahim()
print(murad.sendAMessage())
print(fahim.sendAMessage())