Assume I have an Ingest
object that will only work with objects that implemented the MyInterface
interface. The ingester takes all the said objects but our language does not have complex return types, as such, these objects, when implementing the interfaces, can only be "forced" to implement basic return types. Our interface, at best, will look like this:
interface MyInterface
{
public function someMethod: array;
}
Now, in our ingester, we might decide to loop through all of our objects:
for( $objects as $object ) {
print $object->someMethod['key_that_every_object_should_have'];
}
...and we hit an error. Even though the return from someMethod
is indeed an array, it doesn't have the key key_that_every_object_should_have
and so, if we were to have complex return types, could we consider the object reliable?
What are the cases where, even with this, these objects are still not reliable?
I understand reliability is given by what you're trying to do with these objects in other places, but these objects shouldn't change their behavior just because you want to do something with them. They're as-is and they set the boundaries for the outer world.
if item exists in array
.someMethod['key_that_every_object_should_have']
should besomeMethod()['key_that_every_object_should_have']
.someMethod
is returning an associative array, which is more like what other languages call a dictionary, with the keykey_that_every_object_should_have
.