Information générale
Catégorie:
Programmation Orientée Object
This sort of direct printing is a real pain to do. You can handle the different formats for different clients situation by subclassing the printmanager class, but for this to be effective you need to make it as fine grained as possible.
Each printable element, such as invoice amount, description,tax, total etc should be done in its own method. That way you can replace only the formats that need to change.
Also the parent object should have properties that define the current print positions and widths for text items and the methods should always use these methods rather than hard coding their own location.
Then the control method that controls the printing (which will need to be re-written for each format) becomes the place where you set the print position and for each receipt/invoice element and then calls the method that prints the element. You might even find it an advantage to have the control method call three sub-methods, one for header, one for body and one for totals. Then it you had a format that only changed the header you would only need to replace that method.
Finally create a factory object to deliver the correct subclass for the client/printer configuration.
Hope this helps
Andrew
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement