6
I saw a certain class whose statement was that way:
class Collection implements Countable {}
I realized she was implementing Countable
, but I didn’t understand what this implementation was doing there.
What is the purpose of Countable
? This is a standard PHP interface?
My example then was not good, because it is O(n) -- I think.
– bfavaretto
@bfavaretto ideally is not good at all, but does not prevent to use. As I said can do as you see fit. Only that normal, in decent languages :D is expected to the programmer to do O(1), but is not required.
– Maniero
I switched my example to an O(1 implementation) :-)
– bfavaretto
@bfavaretto actually don’t know if that way is O(N), I think she does the same as you are doing. I may be wrong, but all that
count()
of the language accepted to count must have the count stored– Maniero
Capable indeed. But considering the "good practices" you mentioned, I thought it best to leave an example that takes care of its own count.
– bfavaretto
I had forgotten the +1 :p
– Wallace Maxters