On Jun 6, 2015, at 17:04 , Cosmo <[email protected]> wrote:
> 
> Sorry. I was inaccurate in my language. I’m actually calling these methods on 
> the superclass, not on instances of it.

What you’re really doing here is a combination of two standard Obj-C patterns:

1. Singleton pattern. You’re using the class objects (that is, the meta-objects 
that represent the classes themselves) as singleton objects — as the single 
object that implements certain behavior.

There’s nothing absolutely wrong with this, but it’s more usual to create a 
single instance of a class instead of implementing the behavior as class 
methods. There are a few drawbacks to using the class object, the most obvious 
one being that class objects can’t have @property-style properties.

2. Delegation pattern. In “decoupling” the secondary (subclass) objects from 
the primary (base class) object, clients of your class API are sending messages 
to one object, which then has another object do some or all of the work.

In your case, since the API of the primary object and the API of the delegate 
is the same (they respond to the same methods), perhaps it would be more 
accurate to call this a proxy pattern rather than a delegate pattern, but the 
idea is much the same.

Again, there’s nothing absolutely wrong with the way you’re trying to do this, 
but in modern Obj-C the best way is to write the API into a protocol, and to 
have the primary class adopt the protocol. As far as clients of the class are 
concerned, the “decoupled” objects are an implementation detail they don’t care 
about, so the method of delegation is an implementation detail, too. There’s no 
need, for example, for the secondary objects to be subclasses of the primary 
object. For simplicity, you can choose to just make the secondary objects 
conform to the same protocol.

I’d avoid calling this “forwarding”, because that term has a very specific 
meaning in Obj-C. There is in fact a formal method forwarding mechanism, but 
you’ve re-invented it informally.

In terms of what’s currently going wrong, you have all the information you need 
to debug this. You can set breakpoints, and you can examine the result of 
'[self classToUseForBackend]’ in the debugger, so you should be able to see 
what’s going on.



_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to