This question already has an answer here:

This is what I am doing,

Creating a new Pdf document using Aspose Pdf

Adding few different types pages you know introduction page, table of content pages etc...

Adding some further documents to it [just created pdf].

Not sure which pattern to use.

I am thinking about creating classes for different types of pages to create specific pages, as different departments can ask for different introduction pages or different layout of table of contents and so on...

Page type classes will have a contruct which will create the page and return the pdf component back.

for each different layout i will create a new page.

marked as duplicate by Kilian Foth, Bart van Ingen Schenau, user53019, user40980, gnat Jan 18 '15 at 20:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    @KilianFoth erm... don't think so – Mathematics Jan 14 '15 at 12:13
  • 7
    Asking which pattern to use is the wrong approach. What matters is how to solve the problem. That solution may or may not make use of some standard design pattern. – CodesInChaos Jan 14 '15 at 12:24
  • Strategy pattern so far makes sense to me – Mathematics Jan 14 '15 at 12:48
  • I am under the impression whenever someone asks here on this site "which design pattern", someone else (or in this case the OP) answers "strategy pattern" like a reflex - regardless if that is a good fit or not ;-) – Doc Brown Jan 14 '15 at 13:31
  • 3
    Design patterns are a means to an end - not the end in themselves. Trying to pick a design pattern so you can start programming is a classic case of cargo cult programming. You'd be far better off learning the patterns and then recognising them in your various problem domains. – Robbie Dee Jan 14 '15 at 16:07

IMHO you are approaching this from the very wrong end. You ask for avoiding duplicate code where it seems you do not have any (or at least not much) code so far.

Better start implementing the code for creating one or two PDFs, and whenever you are tempted to copy/paste a piece of code, stop for moment, step back and think if you can avoid the duplication by refactoring the common parts into a single function. Whenever you have to deal with data forming a group which belongs together, try to introduce a struct or a class. And when you note you have isolated operations on that data, refactor to member functions of the created class. When you notice you have similar requirements in different classes, refactor those out to helper classes, common base classes and in the end resusable libraries.

When you follow that path, you may come to a point when you have written real code where you have problems to isolate commonalities - then is a good time to present the problem here, or on stackoverflow.com, or on codereview.stackexchange, and ask if there is a design pattern which can help you.

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