Why is WaveItem class not abstract? #79

Closed
christophe-dooapp opened this Issue Oct 7, 2013 · 6 comments

Comments

Projects
None yet
2 participants
@christophe-dooapp

I just create a new WaveItem by this code :

public static final WaveItem CONTAINER_KEY = new WaveItem("CONTAINER_KEY");

It throws me complicated ClassCastException, and I lost about 30min to understand that I need to override the WaveItem class by this code :

public static final WaveItem CONTAINER_KEY = new WaveItem("CONTAINER_KEY") {
};

As far as it's mandatory to use this class why don't make this class abstract?

@ghost ghost assigned sbordes Oct 7, 2013

@sbordes

This comment has been minimized.

Show comment
Hide comment
@sbordes

sbordes Oct 7, 2013

Member

The WaveItem is used to hold a type that will be used as a method parameter, or within a WaveData wrapper.

So your code should be

public static final WaveItem CONTAINER_KEY = new WaveItem("CONTAINER_KEY") {
};

I will review your proposition for refactor it as Abstract class, there is another improvment I want to add related to attach a unique name dynamically (like the enum name() does, but I didn't find the most stylish way)

Member

sbordes commented Oct 7, 2013

The WaveItem is used to hold a type that will be used as a method parameter, or within a WaveData wrapper.

So your code should be

public static final WaveItem CONTAINER_KEY = new WaveItem("CONTAINER_KEY") {
};

I will review your proposition for refactor it as Abstract class, there is another improvment I want to add related to attach a unique name dynamically (like the enum name() does, but I didn't find the most stylish way)

@christophe-dooapp

This comment has been minimized.

Show comment
Hide comment
@christophe-dooapp

christophe-dooapp Oct 7, 2013

In fact, I based my request on Google Guice TypeLiteral. (It use the same system as yours to handle generics)

http://google-guice.googlecode.com/git/javadoc/com/google/inject/TypeLiteral.html

In fact, I based my request on Google Guice TypeLiteral. (It use the same system as yours to handle generics)

http://google-guice.googlecode.com/git/javadoc/com/google/inject/TypeLiteral.html

@sbordes

This comment has been minimized.

Show comment
Hide comment
@sbordes

sbordes Oct 7, 2013

Member

But TypeLiteral is not an abstract class ?

What do you think if I write this warning into the (wip) documentation ?

Don't forget the {} for WaveItems !

I could change the default constructor visibility like they do

protected TypeLiteral() {...}

It will have a lower impact thantdeclaring the class abstract.

I will pushed it tonight on 0.7.6-SNAPSHOT version

Member

sbordes commented Oct 7, 2013

But TypeLiteral is not an abstract class ?

What do you think if I write this warning into the (wip) documentation ?

Don't forget the {} for WaveItems !

I could change the default constructor visibility like they do

protected TypeLiteral() {...}

It will have a lower impact thantdeclaring the class abstract.

I will pushed it tonight on 0.7.6-SNAPSHOT version

@sbordes sbordes closed this in 1fe7aa8 Oct 7, 2013

@christophe-dooapp

This comment has been minimized.

Show comment
Hide comment
@christophe-dooapp

christophe-dooapp Oct 8, 2013

Tank you.

For me, abstract class or protected constructor are the same when you use it.

Tank you.

For me, abstract class or protected constructor are the same when you use it.

@sbordes

This comment has been minimized.

Show comment
Hide comment
@sbordes

sbordes Oct 8, 2013

Member

But 'conceptually' an abstract class requires at least one abstract method.
Protected constructors fit perfectly the need

Thanks for the feedback, I still have to greatly improve documentation, don't hesitate to contact me for any question

Member

sbordes commented Oct 8, 2013

But 'conceptually' an abstract class requires at least one abstract method.
Protected constructors fit perfectly the need

Thanks for the feedback, I still have to greatly improve documentation, don't hesitate to contact me for any question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment