Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Feb 8 '13 at 15:47

This question came from our site for professional and enthusiast programmers.

    
Cannot help unless you explain what a Mojo is. –  user61852 Apr 1 '13 at 12:52

2 Answers 2

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?

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.