Re: Appropriate dealloc and finalize actions
Re: Appropriate dealloc and finalize actions
- Subject: Re: Appropriate dealloc and finalize actions
- From: Greg Guerin <email@hidden>
- Date: Sun, 11 Oct 2009 16:11:07 -0700
Karolis Ramanauskas wrote:
- (void)dealloc {
if (self.connection) {
self.connection.connection = nil;
}
[super dealloc];
}
Why would you do this? You're making one object responsible for the
internals of another object. This is a bad idea. It breaks the
individual encapsulation of each object.
One of the cardinal points of good object-oriented design is that an
object's responsibilities are circumscribed. It should manage itself
and the things it directly references, nothing else. For any objects
it DOES reference, each of those objects also has its own
responsibilities, and so on recursively. Objects shouldn't poke
their noses into another object's business.
If you want to do something that doesn't break encapsulation, then
you should simply release the one ivar connection. That will let the
receiving object perform its own actions, by itself, on its own
behalf, as appropriate to its own affairs.
-- GG
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden