tags:

views:

22

answers:

1

I know that you can do one of the following things when declaring the type of a variable in objective c:

id obj0;
MyClass *obj1;
id<MyProtocol> obj2;

What i'm curious about is if this is valid (syntactically and semantically):

MyClass<MyProtocol> *obj3;

What i want is to store a cocoa class that must implement a given protocol in this variable; if i had control over "MyClass" i wouldnt need this but i'm basically wondering if i can get away with not having to make my own abstract class that multiple other disparate classes need to inherit from, when they can otherwise just inherit from "MyClass" directly.

+2  A: 

Yes.

MyClass<MyProtocol> *obj3;

means that obj3 should be a pointer to an object of type MyClass or a subclass, that also implements MyProtocol.

mipadi