Consumer Pattern'Consumer Pattern' - work in progress
Description
You have a group of objects that you would like to use in a certain way depending on what the object actually is.
Example
public interface Product {
}
public class GoodProduct implements Product {...}
public class HazardousProduct implements Product {...}
public class RecalledProduct implements Product {...}
...
public class ConsumeProduct {
private final ConsumeProduct CONSUMER = new
ConsumeProduct();
private ConsumeProduct() {}
public getInstance() {
return CONSUMER;
}
public boolean test(Product p) {}
Uh, the above definition is an error in Java; if a function is declared to return a boolean, it should either be abstract or in fact return a boolean. I assume you meant something else, delete when fixed.
public void use(Product p) {}
public void tag(Product p, Tag t) {}
...
}
public class Application {
RecalledProduct rp;
rp = new RecalledProduct();
if (ConsumeProduct.test(rp)) {
ConsumeProduct.use(rp);
}
else {
ConsumeProduct.tag(rp, Tag.BAD);
}
...
}
Note
Not sure if this Pattern is already defined. It is similar to VisitorPattern but not really sure... comments are welcome.
Comments
I know that this page is a work in progress, but what is this pattern used for? Much of the Java code looks suspicious, and it appears that instantiating a ConsumeProduct? retroactively instantiates another ConsumeProduct?, and so on...a recursive class definition that never terminates is not a good thing. Perhaps you left out a "static" declaration; it almost appears you are trying for SingletonPattern, given that you have a method named getIntance()???
EditText of this page
(last edited June 25, 2004)
or FindPage with title or text search