I like the pattern concise and simple, in our service class:
Action action = Action.parse(request.getAction());
action.doAction();
If I migrate them to static inner class, would it be like this?
Action action = ActionFactory.create(request.getAction()));
action.doAction();
klc
On Tuesday, May 26, 2015 at 11:54:56 PM UTC+8, Nate Bauernfeind wrote:
>
> What is it that you like about the pattern that you want to keep? Are you
> looking for static inner classes? You can couple the pattern with an
> assisted inject factory, or providers depending on your use case.
>
> public abstract class Action {
> public abstract double doAction();
>
> public static class ADD extends Action {
> @Override
> public double doAction() { ... }
> }
>
> public static class UPDATE extends Action {
> @Override
> public double doAction() { ... }
> }
>
> public static class DELETE extends Action {
> @Override
> public double doAction() { ... }
> }
> }
>
> Nate
>
> On Tue, May 26, 2015 at 7:06 AM klc <[email protected] <javascript:>>
> wrote:
>
>> Hi guys, thanks for all the reply before I have migrate my servlet
>> application to guice, partly at least.
>>
>> I have a question about design, we use the enum template pattern a lot,
>> like this:
>>
>> public enum Action {
>> ADD {
>> @Override
>> public double doAction() {...}
>> },
>> UPDATE {
>> @Override
>> public double doAction() {...}
>> },
>> DELETE{
>> @Override
>> public double doAction() {...}
>>
>> public abstract double doAction();
>>
>> }
>>
>> This is great pattern and I have nothing against it, but you can't inject
>> it into other class and can't inject anything into it.
>> Is there a similar way to do the same, but injectable?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "google-guice" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/google-guice.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/google-guice/3f1c0641-b8c1-4391-aab7-81e8e05608d8%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/a9aac798-6830-444e-b7b3-b9dd5744bbb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.