Lets say my file will have 3 paragraphs A, B, C, and you can build each paragraph in 3 different ways

At the end you end up with something like A1, B2, C3 or A1, B1, C1 or A2, B1, C2 and so on

I already did this with a lot of IFs, and the ugliest part was the fact that each class had parameters of the following ones. For instance A receives 3 parameters and passes 2 to B, then B passes the last one to C

This is not extensible or maintainable at all, I really feel everything is chained and I want to break the chain, so how can I implement this neatly?

I am not able to completely understand your problem. Some code would surely help. Also, have you considered your inheritance structure might be causing the trouble?
–
darnirNov 25 '11 at 6:41

Good question, you managed to stumble on a good design pattern. Let me know if you want me to hash out some code as an example, I barely know Java but I could get close.
–
Devin MNov 25 '11 at 6:43

I'll try to add some code, there is no inheritance at all, think of my problem like if you want to assemble a car, and have 3 sections on the assembly line. Each section needs to do something and there is many ways to do it, in addition I want the instructions to be passed globally instead of A telling B what B & C need to do
–
pmminovNov 25 '11 at 6:46

Cool, this one worked, I have my main (which I named JobHandler), with an small factory pattern that picks one of the three strategies for each part, and then I execute 3 context calls XD.
–
pmminovNov 25 '11 at 7:13

Well if it works for you then that's good. Good luck with the project.
–
Devin MNov 25 '11 at 21:34

Did you consider using chain of responsibility pattern to this problem? All it does is to pass the input through series of processing objects and the objects take the responsibility in deciding whether it will serve the current request and/or pass on the output to the next object in line.

I suppose not. Objects don't take any responsibility in doing anything. You create objects you use it. How can the objects take responsibility in any program? In this pattern the objects decide to serve the input request based on some condition and that is not decided at runtime by the developer
–
AjaiNov 25 '11 at 6:52

Perfect.. And AFAIK, that concept stands at the core of a good OO-Design.. Do correct me if I'm wrong..
–
darnirNov 25 '11 at 6:55

I think you are mistaken. The responsibility that I mentioned above is the runtime decision made by the object whether to serve the current input request. Since the person who asked the question mentioned that the input has to pass through a series of steps and each one has to pass on some parameters to the subsequent one I thought this pattern would be a match
–
AjaiNov 25 '11 at 6:59

Could the Decorator pattern be of use here? My assumption is that you start by letting the user choose which first paragraph he'd like to use (ParagraphA extends AbstractParagraph). Then you let user choose which second paragraph to use (ParagraphB extends AbstractParagraph) and you wrap ParaghraphA with ParagraphB. At the end you let the user choose which third paragraph to use (ParagraphC extends AbstractParagraph) and you wrap ParagraphB with ParagraphC.

At the end, you build the file by invoking ParagraphC#getText() which then travels up the entire chain (using super.getText()) to merge all paragraphs.