| > What an object is, which is roughly equivalent to its observed behavior, should never depend on how it is declared. This is actually a statement that strong typing should not exist. A "declaration" (really a type declaration) indicates the type, and if observed behavior cannot depend on the types there is not much point to types. Or stated positively: in a strongly typed language, the types are part of 'what an object is'. Or, stated by example: let a: Int = 3
let b: Float = 3
print(a/2) //prints 1
print(b/2) //prints 1.5
Both a and b are "the same" value, insofar as they are `==` and they model the same underlying mathematical concept. But behavior varies because they differ in type.OP's snippet actually works quite a lot differently than the way you may expect; LazyGreeter.greet() and Greeter.greet() are two completely independent functions that share the same name. Name resolution is a complex topic in any language, but in Swift if you wanted to override another function you would say `override`, in which case the compiler will complain there is nothing you can override in `BaseGreeter` at which point you will understand the whole mistake. There is actually no way to "pick" LazyGreeter's implementation of the unrelated function (as perhaps you expect). The only function we can call on a Greeter is Greeter.greet (or its overloads, and there are none). So if Greeter.greet did not exist, we would not get LazyGreeter.greet() but rather a type error. I do think a case can be made that we need a similar `implements` keyword like `override` to check that we are implementing a protocol requirement. |
Nope. It is a statement that objects shouldn't be different depending on how you look at them.
The example is a class, so a reference type. That means that greeter and greeter1 are just two references to the exact same underlying object.
Your example are two distinct value type instances that you happened to initialize from the same literal.
So not even close to comparable situations. Speaking of comparable:
> Both a and b are "the same" value, insofar as they are `==`
Also nope.
Let's compile this: