Re: Abstract Factory of Factory??
- From: Robert Martin <unclebob@xxxxxxxxxxxxxxxx>
- Date: Sun, 28 May 2006 12:31:13 -0500
On 2006-05-25 23:16:15 -0500, "Saurabh Aggrawal" <games60@xxxxxxxxxxx> said:
I have application called "Client" whose function is to monitor the
status of application "Server". Client is polling Server every 2
seconds for its current status. Server's status could be X, Y, Z, XX
,YY ,ZZ. Depending on the state of the Server the Client will popup a
dialog box that will be different for all the state's of Server. i.e
for the status X in Server the Client has dialog box DiaX in it.
Similarly DiaY, DiaZ and so on.....
-------------
| |
| Status |
----|---------
|
|
|--------|-------|--------|--------|---------|
X Y Z XX YY ZZ
------------
| |
| Dialog |
----|---------
|
|
|--------|-------|--------|--------|---------|
DiaX DiaY DiaZ DiaXX DiaYY DiaZZ
and the code goes like this:----
if(Status == iX)
{
X = new X();
DiaX = new DiaX();
}
else if(Status == iY)
{
Y = new Y();
DiaY = new DiaY();
}
........
.......
.......
......so on
Could you please suggest me which pattern to use, Fatory Pattern or
Abstract Factory Pattern. I think i am having problems understanding
them.
Thanks,
Saurabh Aggrawal
It seems to me that the factory you need looks like this:
public Client {
private ServerState serverState = null;
public void PollServerStatus() {
setServerState(getServerStatus());
}
public String getServerStatus() {
....
}
public void setServerState(String stateName) {
serverState = StateFactory.makeState(stateName);
serverState.showDialog();
}
}
public interface ServerState {
public void showDialog();
}
public class StateFactory {
private Map stateDictionary = new HashMap();
public StateFactory() {
stateDictionary.add("X", new StateX());
stateDictionary.add("Y", new StateY());
...
}
public ServerState makeState(String stateName) {
return stateDictionary.get(stateName);
}
}
public class StateX implements ServerState {
public void showDialog() {
Dialog d = new DialogX();
d.show();
}
}
.....
--
Robert C. Martin (Uncle Bob) | email: unclebob@xxxxxxxxxxxxxxxx
Object Mentor Inc. | blog: www.butunclebob.com
The Agile Transition Experts | web: www.objectmentor.com
800-338-6716 |
.
- References:
- Abstract Factory of Factory??
- From: Saurabh Aggrawal
- Abstract Factory of Factory??
- Prev by Date: Re: Mixins, Multiple Inheritance, Interfaces
- Next by Date: Re: Searching OO Associations with RDBMS Persistence Models
- Previous by thread: Re: Abstract Factory of Factory??
- Next by thread: Facade
- Index(es):