Extending classes with generic params

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Extending classes with generic params

David Peek
Hi List,

Is it possible to do something like this?
ClassA<T> extends ClassB<T>

Basically I have abstract generic Behavior<T> with property target:T.

So that when I subclass:
ScrollBehavior extends Behavior<Sprite>

The compiler knows that "target" in ScrollBehavior is a Sprite.

But what if I want another abstract subclass? For example:
SpriteBehavior<T:Sprite> extends Behavior<T>

Such that SpriteBehavior passes the type to it's super class, and is allowed a target of anything subclassing Sprite. Sorry for the clumsy explanation, not quite sure of the right terms :)

Cheers,
David
--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Extending classes with generic params

Tony Polinelli

ClassA<T> extends ClassB<T>

definately works.

If you wanted a subclass to force Sprite, wouldnt you just say:

ClassA extends ClassB<Sprite>

?


On Tue, Mar 1, 2011 at 9:34 AM, David Peek <[hidden email]> wrote:
Hi List,

Is it possible to do something like this?
ClassA<T> extends ClassB<T>

Basically I have abstract generic Behavior<T> with property target:T.

So that when I subclass:
ScrollBehavior extends Behavior<Sprite>

The compiler knows that "target" in ScrollBehavior is a Sprite.

But what if I want another abstract subclass? For example:
SpriteBehavior<T:Sprite> extends Behavior<T>

Such that SpriteBehavior passes the type to it's super class, and is allowed a target of anything subclassing Sprite. Sorry for the clumsy explanation, not quite sure of the right terms :)

Cheers,
David
--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Extending classes with generic params

jlm@justinfront.net
on a side note...

I would not advise creating complex inheritance Sprite structures.

View Logic structures are not the same as Visual Structures, so I don't inherit from Sprite or MovieClip, many disagree.


On 1 Mar 2011, at 01:17, Tony Polinelli wrote:


ClassA<T> extends ClassB<T>

definately works.

If you wanted a subclass to force Sprite, wouldnt you just say:

ClassA extends ClassB<Sprite>

?


On Tue, Mar 1, 2011 at 9:34 AM, David Peek <[hidden email]> wrote:
Hi List,

Is it possible to do something like this?
ClassA<T> extends ClassB<T>

Basically I have abstract generic Behavior<T> with property target:T.

So that when I subclass:
ScrollBehavior extends Behavior<Sprite>

The compiler knows that "target" in ScrollBehavior is a Sprite.

But what if I want another abstract subclass? For example:
SpriteBehavior<T:Sprite> extends Behavior<T>

Such that SpriteBehavior passes the type to it's super class, and is allowed a target of anything subclassing Sprite. Sorry for the clumsy explanation, not quite sure of the right terms :)

Cheers,
David
--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Extending classes with generic params

Tony Polinelli
i would be one ;P  Depends on the usage - for libraries, code well, for production on small jobs, code smart ;P



On Tue, Mar 1, 2011 at 12:39 PM, [hidden email] <[hidden email]> wrote:
on a side note...

I would not advise creating complex inheritance Sprite structures.

View Logic structures are not the same as Visual Structures, so I don't inherit from Sprite or MovieClip, many disagree.


On 1 Mar 2011, at 01:17, Tony Polinelli wrote:


ClassA<T> extends ClassB<T>

definately works.

If you wanted a subclass to force Sprite, wouldnt you just say:

ClassA extends ClassB<Sprite>

?


On Tue, Mar 1, 2011 at 9:34 AM, David Peek <[hidden email]> wrote:
Hi List,

Is it possible to do something like this?
ClassA<T> extends ClassB<T>

Basically I have abstract generic Behavior<T> with property target:T.

So that when I subclass:
ScrollBehavior extends Behavior<Sprite>

The compiler knows that "target" in ScrollBehavior is a Sprite.

But what if I want another abstract subclass? For example:
SpriteBehavior<T:Sprite> extends Behavior<T>

Such that SpriteBehavior passes the type to it's super class, and is allowed a target of anything subclassing Sprite. Sorry for the clumsy explanation, not quite sure of the right terms :)

Cheers,
David
--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org