Ben Two

Ranch Hand
+ Follow
since Jul 06, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Ben Two

Faint

" Let's assume every PizzaStore has their code fragment of cutting, baking ,etc. The evidence is the first paragragh in page 119"

What I've done is not to support my opinion, but put on more code for the PizzaStore working with SimpleFactory which support the words in the book.

If you don't agree me, could you please tell me why the author said we need more quality control?

PizzaStore is a concrete class with SimpleFactory

public PizzaStore
{
public PizzaStore(SimpleFactory factory)

public Pizza orderPizza(String type)
{
Pizza pizza;
pizza=factory.createPizza(type);
pizza.prepare(); // this line can be removed or replaced by various pizzastore, for example local method: prepare(pizza);
pizza.bake(); //this line can be removed or replaced by various pizzastore, for example local method: bake(pizza);
pizza.cut(); //this line can be removed or replaced by various pizzastore, for example local method: cut(pizza);
pizza.box();// this line can be removed or replaced by various pizzastore, for example local method: box(pizza);

}

}

From the above code, could you please tell me is it possible that different concrete pizzastore use different process(prepare, bake, cut, box)? If the answer is yes, then is it a worse solution since it lost quality control?

I'm afraid that is what I can say, if you don't agree I give up.
Hi, I made a mistake by saying "Each subclass of SimleFactory implement their own process", it should be

Each PizzaStore aggregated with a SimpleFactory implement their own process

class PizzaStore {

public PizzaStore(SimpleFactory factory)
{ .... }
Pizza orderPizza(String type)
{ Pizza pizza=factory.createPizza(type);
prepare(pizza);
bake(pizza);
cut(pizza;
box(pizza);
return pizza;
}
}

The detail of the orderPizza method does not appear in the book but you can assume this from the paragraph in that page.
Hi Kamal

First, if you insist SimleFactory only handle create not process, then it lose the quality control, please refer to the above code I attached, Every PizzaStore has their own process.

Second, if you want to put the create and process together as an improvement which you put forward above. Then there is no real difference.

Originally posted by Mohamed Farouk:
Thanks again
But i prefer a facade as it provides an interface to the business layer
So if i use a facade can it be SL holding a reference to SF and other SL session beans?



Hi, ofcourse you can, but remember:

In this case, when you first call the Facade to get a SF VL reference, Later you will deal with this VL directly, without further interaction with the Facade.

Originally posted by Kamal Mettananda:
Can we consider aggregating two operations like "creation (create method)" and "process (prepare, cut etc methods)" into one class as an improvement?



Hi Kamel,

If you consider this improvement, then there is no real difference. But since SimpleFactory did seperate create and process. It's a worse design since every subclass of SimpleFactory implement their own process which lose quality control

regards
Ben
Hi Kamal

Ofcourse I read your reply.

Now I'd like to explain more on the difference between SimpleFactory and AbstractPizzaStore which is actually a Abstract Factory using Template Method.

with SimpleFactory, you can refer to Page 117
PizzaStore aggregate a SimplePizzaFactory, SimplePizzaFactory create and return an abstract class Pizza with prepare, bake ,cut, box operations, and CheesePizza, VeggiePizza extend the abstract Pizza, so they have their own prepare, bake ,cut, box which is different.

Before:

class NYSimpleFactory extends SimpleFactory
{
Pizza createPizza(String type){
//creates Newyork specific
Pizza pizza;
if (type.equals("cheese")) pizza=new NYStyleCheesePizza();

return pizza;
}}

class PizzaStore {
public PizzaStore(SimpleFactory factory)
{ .... }
Pizza orderPizza(String type)
{ Pizza pizza=factory.createPizza(type);
pizza.prepare();
pizza.bake();
pizza.cut();
pizza.box();
return pizza;
}
}

After:

public abstract class PizzaStore
{
abstract Pizza createPizza(String type);
public Pizza OrderPizza(String type)
{
Pizza pizza=createPizza(type);
pizza.prepare();
pizza.bake();
pizza.cut();
pizza.box();
return pizza;
}


public class NYStylePizzaStore
public Pizza createPizza(String type)
{
if (type.equals("cheese")) return new NYStyleCheesePizza();
......
}

Now the biggest different of two solution is two class PizzaStore and SimpleFactory combined into one class, the Concrete PizzaStore.

Client invocation change from

SimplePizzaFactory factory=new NYStylePizzaFactory();
PizzaStore store=new PizzaStore(factory);
store.orderPizza("cheese");

into
PizzaStore store=new NYStylePizzaStore();
store.orderPizza("cheese");

If you read the second to the last paragragh of page 119
"Rethinking the problem a bit, you will see that what you'd really like to do is create a framework that ties the store and the pizza creation together, yet still allow things to remain flexible"

So in my opinion the only improvement is, No aggregation from PizzaStore to SimpleFactory is needed. In a word, 2 in 1.
And for the quality control, Let's assume every PizzaStore has their code fragment of cutting, baking ,etc. The evidence is the first paragragh in page 119
"the franchises are were using your factory to create pizza, but start to employ their own procedure for the rest of the process, bake differently, cut differently, use different box"
Hi

If the VL Bean reference is returned at the first call to the Session Facade, what is the differece between this approach and call VL SFSB directly without invovling the SessionFacade?

I think Facade is just a kind of proxy and delegate so Facade is not necessary if your background beans are not complicate.
If you have to use SFSB for the VL, the second solution seems to be the only choice, because it's impossible to acccess the same stateful VL through SLSB.
Hi Kamal

Do you catch the meaning of Quality Control?

It does not mean the quality of your Factory Method design, it means the quality control of Pizza creation.

Every pizza factory has it's own style of boxing, cutting, etc. That's the point that the author want to use the same boxing , cutting, for all the factory. That is Quality Control. This is a business vocabulary, not software here.
Hi, maybe you can try a Adapter

When the C is replaced by C', don't remove C from your library, you can rewrite the C, for example

F constructor, public F(C c);
some F method contains c.execute();

then you can replace the code in c.execute into

public void execute()
{
C' c2=new C'();
c2.anotherExecute();
}

Then for different version you just pick different C.
Hi Kamal

If you read the text in page 119 you will find the explanation.

For SimpleFactory, the pizza creation code is written in different Factory, then the prepare, bake, cut, box will be different, that's the reason why the author said 'a little more quality control'.

In the next page a Template Method pattern is used to work with the Abstract Factory. Then for all the pizza store, only the creatpizza method is different since the toppings, dough, sauce are different.
For me maybe Decorator pattern is useful

You can define an interface which will be configured into your AOP config xml. Then you can implement the interface by different class like Validation, Security. For each class the there is a constructor with the parameter of this interface.

public interface IAdvice
public void execute()

public class ValidationAdvice()
public ValidationAdvice(IAdvice advice)

.....other implement class.....

Finally you can define a List just like the InterceptFilter config, or simply wrap the impl class like new FinalAdvice(new SecurityAdvice(new ValidationAdvice()))

At last you can add as much decorator class as you want and config the classname into the xml files for your AOP.
Service Locator is still useful if there is a demand for connectiong RMI or Web Service and other remote services. I think it's an extension of GoF proxy pattern. Also ValueListHandler can be used in other circumstance except for caching the DAO result set.

For composite entity, I think it's sort of out-of-date since GoF Composite pattern is more accurate and generic
Great explanation!

I'd like to add an example.

For a GUI application, you may find there is a recent file list under File menu and also an Undo button in the menubar.

The recent file list is a classic example for Memento pattern and the Undo button is a Command pattern.
Hi

Capture mobile button action in J2ME Midlet, possible
Capture mobile button action in PC Java program, seems impossible

regards
Ben
17 years ago