Created
April 18, 2012 11:52
-
-
Save heyLu/2413094 to your computer and use it in GitHub Desktop.
jSOMP: Alternative MVC architecture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jsomp.example.mvc; | |
/* | |
* A MVC example not using reflection in the controller. | |
*/ | |
interface Machine { | |
String getName(); | |
void setName(String name); | |
float getFailureProbability(); | |
void setFailureProbability(float failureProbability); | |
float getRetoolTimeFor(String fromOperation, String toOperation); | |
void setRetoolTimeFor(String fromOperation, String toOperation, float retoolTime); | |
Set<String> getOperations(); | |
void setOperations(Set<String> operations); | |
} | |
class TrivialMachine implements Machine { | |
private String name; | |
private float failureProbability; | |
private Map<OperationPair, Float> retoolTimes; | |
private Set<String> operations; | |
TrivialMachine() {} | |
String getName() { | |
return this.name; | |
} | |
void setName(String name) { | |
this.name = name; | |
} | |
float getFailureProbability() { | |
return this.failureProbability; | |
} | |
void setFailureProbability(float failureProbability) { | |
this.failureProbability = failureProbability; | |
} | |
float getRetoolTimeFor(String fromOperation, String toOperation) { | |
ops = new OperationPair(fromOperation, toOperation); | |
return this.retoolTimes.get(ops); | |
} | |
void setRetoolTimeFor(String fromOperation, String toOperation, float retoolTime) { | |
ops = new OperationPair(fromOperation, toOperation); | |
this.retoolTimes.put(ops, retoolTime); | |
} | |
Set<String> getOperations() { | |
return this.operations; | |
} | |
void setOperations(Set<String> operations) { | |
this.operations = operations; | |
} | |
private class OperationPair implements { | |
private final String firstOperation; | |
private final String rightOperation; | |
OperationPair(String firstOperation, String secondOperation) { | |
this.firstOperation = firstOperation; | |
this.secondOperation = secondOperation; | |
} | |
boolean equals(OperationPair otherPair) { | |
return this.firstOperation.equals(otherPair.firstOperation) && | |
this.secondOperation.equals(otherPair.secondOperation); | |
} | |
} | |
} | |
class WorkflowController { | |
private List<Machine> machines; | |
WorkflowController(List<Machine> machines) { | |
this.machines = machines; | |
} | |
MachineI getMachine(int n) { | |
return this.machines.get(n); | |
} | |
float getRetoolTimeFor(int n, String fromOperation, String toOperation) { | |
return this.machines.get(n).getRetoolTimeFor(fromOperation, toOperation); | |
} | |
/* ... */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment