java - Call subclasses with static methods -
i need behavior of calling subclass methods statically. in example have group of messengers
. need call once or twice in each implementation, not feel keeping variables of super interface since need have 1 method description all, or several obliged overwrite. , not static.
i want able messenger.messageerrormessage.send(param)
or messenger.messagedefaultmessage
, etc... need bind them superclass, still keep static behavior when calling subclass methods.
so i've done below: interface has public innerclasses call subclass static methods change in name being messageerrormessages
(actual subclass) messageerrormessage
(inner class) need change name plural name singular name.
interface messenger{ public static final class messageerrormessage{ public static void send(message message){ messageerrormessages.send(message); } } public static final class messagedefaultmessage{ public static void send(message message){ messagedefaultmessages.send(message); } } }
the actual implementation of interface messenger..
messageerrorsmessages implements messenger { public static void send(message message){ //..implementation of send } }
the actual implementation of interface messenger..
messagedefaultmessages implements messenger{ public static void send(message message){ //..implementation of send } }
this way don't have keep in mind 20 different types of messenger
subclasses , needing keep variables. breaking design rules?
edit: want able write
messenger.messageexception.send(message, throwable);
and @ same time
messenger.messagedefaultmessage.send(message);
i want subclasses own unique behaviour , method decklarations still collected under messenger.
i'm not sure trying accomplish (i'm not sure understand question) seems want override static methods in subclasses can call method on instance , have delegate subclass method. not possible. static methods called on class call them on (note call static methods on class, not on instance. compilers/ides throw warning if try call static method on instance because can obscure class calling on).
Comments
Post a Comment