Reputation: 97
I have a private function in class A. Class A creates an instance of class B and sends it a reference to this private function. Class B later uses this function. It all works fine, but I'm not sure this is proper OOP. I'm doing it in AS3.
Upvotes: 1
Views: 49
Reputation: 4750
Yes, it is proper. You'll probably have a couple of people who say otherwise, but I'll have to disagree with them.
Something you'll see a LOT of in AS3 is event listeners:
someObject.addEventListener(someEventType, someFunction);
It is very common for someFunction
to be a private function in a different class than someObject's
, and it is considered a completely proper practice. And since this isn't a violation of good OOP - and it is widely considered proper - the same should hold for vanilla callbacks. Callbacks / event listeners are something that really does need to be generally allowed in programming, even OOP languages.
What would be bad is if each class knew about the other, and you had both of them calling each other's functions instead of using event listeners or other callbacks.
Upvotes: 4