Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #28736
| From | Steven Simpson <ss@domain.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: use case for extending enum, but this is not possible in java |
| Date | 2014-06-15 01:04 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <lh4v6b-3m7.ln1@s.simpson148.btinternet.com> (permalink) |
| References | <lniljr$8h9$1@news.m-online.net> |
On 15/06/14 00:24, Laura Schmidt wrote:
> In an application, there is an enum ListCommand that enumerates the
> commands a user may execute on list entries:
>
> public enum ListCommand
> {
> OPEN,
> EDIT,
> DELETE;
> }
>
> There is an interface that uses this enum:
>
> public interface ListCommandProcessor
> {
> void onListCommand (ListCommand cmd);
> }
>
> And there is a generic Listing class that is used to show customized
> lists in the GUI and which uses the above interface:
>
> public class Listing<T>
> {
> ...
> ListCommandProcessor processor;
> ...
> }
>
> So far, so good.
>
> Now I am making a cut: The generic class Listing<T> should be moved
> into a generic java library, so that it can be used by different
> applications. So I also need to move the interface ListCommandProcesor
> into this library, and this would implicate that I also move the enum
> ListCommand into the library. But the enum ListCommand ist application
> specific. If I move it to the library, it must be extendable somehow.
Does your Listing class demand anything of ListCommand? Does it even
require it to be an enum? If not, does this help?:
// In library
public interface Processor<E> {
void onListCommand(E cmd); // inappropriate name now?
}
public class Listing<T, E> {
Processor<E> processor;
public void setProcessor(Processor<E> processor) {
this.processor = processor;
}
}
// In application
public enum AppListCommand {
OPEN, CLOSE, STUFF;
}
public class MyApp extends Processor<AppListCommand> {
{
Listing<XYZ, AppListCommand> listing = ...;
listing.setProcessor(this);
}
public void onListCommand(AppListCommand cmd) {
switch (cmd) { ... }
}
}
Depending on unspecified factors, you might be able to use Processor<?
super E>, or have to use Listing<T, E extends Enum<E>>.
--
ss at comp dot lancs dot ac dot uk
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
use case for extending enum, but this is not possible in java Laura Schmidt <ls@mailinator.com> - 2014-06-15 01:24 +0200 Re: use case for extending enum, but this is not possible in java Steven Simpson <ss@domain.invalid> - 2014-06-15 01:04 +0100 Re: use case for extending enum, but this is not possible in java Marcel Müller <news.5.maazl@spamgourmet.org> - 2014-06-15 02:53 +0200 Re: use case for extending enum, but this is not possible in java markspace <markspace@nospam.nospam> - 2014-06-14 18:58 -0700 Re: use case for extending enum, but this is not possible in java Robert Klemme <shortcutter@googlemail.com> - 2014-06-15 12:20 +0200 Re: use case for extending enum, but this is not possible in java Robert Klemme <shortcutter@googlemail.com> - 2014-06-15 12:21 +0200 Re: use case for extending enum, but this is not possible in java "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-06-15 11:58 +0100 Re: use case for extending enum, but this is not possible in java Wanja Gayk <brixomatic@yahoo.com> - 2014-06-16 01:08 +0200 Re: use case for extending enum, but this is not possible in java Roedy Green <see_website@mindprod.com.invalid> - 2014-06-15 22:20 -0700
csiph-web