I have code like this:
class A {
func method() { print("method from A") }
}
class B: A {
override func method() { print("method from B") }
}
class C: A {
override func method() { print("method from C") }
}
func run (_ obj: A) {
doIt(obj)
}
func doIt(_ obj: A) {
print("specific logic when object of A class")
obj.method()
}
func doIt(_ obj: B) {
print("specific logic when object of B class")
obj.method()
}
func doIt(_ obj: C) {
print("specific logic when object of C class")
obj.method()
}
let obj = C()
run(obj)
I am getting output:
specific logic when object of A class method from C
but i would expect:
specific logic when object of C class method from C
How should I change the code to get this behavior?