0

I am developing a Mojo(think it as just a usual class) for my custom Maven Plugin. There is an Abstract Mojo at top. I have some other custom Mojos in example which makes server side includes. I have some static variables and some util methods in example get operating system name, fix file separator in order to used operating system etc. I have created an abstract Base Mojo that extends Abstract Mojo and put every common things inside it. When I create a Mojo (i.e. server side includer) I extend it from my Base Mojo. However should I think that I should separate variables and util methods or not and what kind of pattern I should follow.

To make it clear there is:

  • AbstractMojo at top by default (I can not change it)
  • BaseMojo an abstract class that extends AbstractMojo that has util methods and static system variables
  • CustomMojo extends BaseMojo and does its responsibility.

Any ideas how to implement a design for my needs?

asked Feb 7, 2013 at 6:50
1
  • Cannot help unless you explain what a Mojo is. Commented Apr 1, 2013 at 12:52

2 Answers 2

1

I'm wondering, why this was migrated. But anyway:

You shouldn't put everything in a base mojo. That practically makes reusing that code impossible. Just think of the mojo growing and you need to split that mojo up into separate classes. You can't do that if that code has a dependency on the base class of the mojo.

You should create services that provide the functionality you currently have in your base mojo. They are reusable and therefore accessible from other places.

As a general rule of thumb:
YAGNI - You aint gonna need a member declaration in a class that is only intendend to be used by deriving classes. How do you know that it is really used?

answered Feb 13, 2013 at 18:26
0

The pattern depends on what the Mojo classes are doing. The util methods should be moved to a helper or utility class or encapsulated within the class that uses them. Unless BaseMojo is providing common implementations for a behavior which may be over ridden in Custom Mojos, it is not required.

answered Mar 1, 2013 at 18:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.