Plugin patter

Hello everybody,

I need to add to my application a pluggable patter, by which i mean that i would like to add to my base program-function, other several stuffs, which i will later code.

I've seen about the use of a observer/stategy/or even factory patter, but won't my BASE-Application be implied as weel in this selection?

How can i approach it?

Thank everyone in advance.

marco

[418 byte] By [marco.ita] at [2007-10-1 22:07:55]
# 1

Marco,

I follow that you are asking a question about design patterns but I get lost with what you are trying to do.

Perhaps if you could explain again what exactly you are going to be doing with your pluggable code?

Sorry your English is not bad but a few things are being lost in translation.. I am not sure what you mean by implied.

marco.ita at 2007-7-13 8:21:19 > top of Java-index,Java Essentials,Java Programming...
# 2

i apologiaze :))

supposing to have a ClassWhichDoSomething, in this class to have things which i want to be always the same, but things which i want to plug later. As i said i've seen the observer/strategy way but shouldn't i then make modifiable even what i don't want to be?

trying to explain one more:

Transferer {

// code ok

// funcion which i want to redo later on

}

Thank you, sorry :)

marco.ita at 2007-7-13 8:21:19 > top of Java-index,Java Essentials,Java Programming...
# 3

Macro,

Sorry, but it's still not clear (to me at least) what you're asking about. You're being kind of vague, and it's not clear what roles ClassWhichDoSomething and Transferer are supposed to play.

Can you provide a bit more code or pseudocode showing what you want to do, and a bit more detailed explanation?

When you post code, please use [code] and [/code] tags as described in [url=http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips[/url] on the message entry page. It makes it much easier to read.

jverda at 2007-7-13 8:21:19 > top of Java-index,Java Essentials,Java Programming...
# 4

public void myTask() {

// what i don't want ever never to be change by a future plugin

Preparator prep = new Preparator();

prep.prepare();

// what i want

Tool tool = new Tool();

tool.use(prep);

}

that's i think is enought, i want to make pluggable only one part of my implementation

i'm seeking for the right way to do it, i'm not sure i should write another class, to do what that method's class is already suppose to do

thanks

marco.ita at 2007-7-13 8:21:19 > top of Java-index,Java Essentials,Java Programming...
# 5

Have you tried to make an interface or abstract class with the methods that you want to be pluggable? Then, define the class that calls those methods such that it needs that interface or abstract class. You give it an instance of a concrete class that implements that interface or extends that abstract class.

If I understand you right, I did this myself once (with a concrete class that could be extended, but same idea). In my case, if you changed some math functions by extending the concrete class, you could get a different plot, without having to change the calling code.

MLRona at 2007-7-13 8:21:19 > top of Java-index,Java Essentials,Java Programming...
# 6

I posted my previous answer while you posted yours. But, I think that my idea is what you want.

Your Tool should implement an interface that declares a method like this:

interface PreparatorUser // I couldn't think of a good name.

{

public void use(Preparator preparator);

}

Then, Tool would look like (with whatever other methods, constructors, and variables you might need, of course):

class Tool implements PreparatorUser

{

public void use(Preparator preparator)

{

preparator.doSomething();

}

}

MLRona at 2007-7-13 8:21:19 > top of Java-index,Java Essentials,Java Programming...
# 7
thank you MLRon.
marco.ita at 2007-7-13 8:21:19 > top of Java-index,Java Essentials,Java Programming...
# 8
You are welcome. Does it work? If it doesn't, post again. :)
MLRona at 2007-7-13 8:21:19 > top of Java-index,Java Essentials,Java Programming...