Factory method pattern: Difference between revisions

Content deleted Content added
m removed situation link... it's just weird.
m dab object
Line 7:
=== Factory design pattern in Java ===
 
The Factory pattern is useful to solve a common [[problem]]: Very often you'll have to construct an [[Object (computer science)|object]], based on some [[input]], and the [[function]]s inside the object will depend upon the input. A good example would be a [[class (computer science)|class]] to read [[image file]]s and make [[thumbnail]]s out of them. You could, of course, bung them all into one class and have it decide which bit of code to run on its own:
 
 
Line 47:
This [[method]] has the [[advantage]] of abstracting the [[file type]] from the class that calls this ImageReader, but as the number of file types supported gets larger, the code will quickly become huge, unwieldy and hard to maintain.
 
Another [[solution]] that seems possible is to have a separate [[Object (computer science)|object]] for each of these file types:
 
public Interface ImageReader