heh, not sure to who that was directed. Let me just state that I never mind being told that I’m wrong. Hell sometimes I even say things I know are wrong(not the case here) just to provoke a question and/or try to direct the other persons focus in a certain direction. I actually loath people who keep quiet just because they presume ‘I don’t get it’. There is also no need for misplaced ‘respect’.
Knowing that something is wrong is the first step to fixing things. It’s really hard to solve problems your not even aware about.
now, that being said… 
[quote]A ‘model’ shouldn’t contain logic:
[/quote]
Perhaps I should have said something along the lines of: ‘A model shouldn’t contain this kind of stuff:’.
Nah, ‘The actions performed by the model include activating business processes or changing the state of the model.’ http://java.sun.com/blueprints/patterns/MVC-detailed.html making the decision as to fire which business processes is business logic.
Now wikipedia saids:
“It is common to split an application into separate layers that run on different computers: the presentation/user interface (UI) (view), business logic (controller), and data access (model).”
which ‘hits home’ just as much as “all logic is in the Model”
As Mr Gol points out, but he uses a poor example. the problem that your having there is that your actually miss-using and int for age but it’s a lot more time effective then making an age class which can only represent valid ages.
A better example would be Person#isAdult(); which probably returns true or false based on a definition of other facts like age or marital status(as is the case here legally): so something like “return getAge() >= 18 || isMarried()” or perhaps as in other cultures “return hasPassedManhoodTrial()”.
Examining the latter it’s more a series of definitions (which might well be formed through logic*) which is kinda different from the stuff that was quoted there. moreover the type of testXXX kinda fundamental invites inconsistencies. if conditions are met for XXX then XXX needs to be true.
*every evaluation includes logic, using the word logic in the context of programming doesn’t narrow down - it’s kinda like saying ‘stuff’
I get that it was a poor and confusing reply, my bad.
No it should be observing the model; I kinda steered you in the wrong direction there.(sorry for that)
I think the problems come from naming your Model ‘model’, Controller ‘controller’ etc. If you go about it that way your modeling the solution for the problem of your code(wish I could find a better way to say this) You should model your code after The system your trying to represent:
While rock-paper-sissors has easy well understood logic capturing it and seperating stuff into MVC gets a little bit tricky if you add rounds to it.
So pick something like RockPaperSissorsBattle (or just battle) and Round or something.
Alike:
import java.util.ArrayList;
import java.util.List;
public class Battle {
enum Hand {
Rock, Paper, Scissor;
boolean isBetterThan(Hand other) {
return this.equals(Paper) && other.equals(Rock) ||
this.equals(Scissor) && other.equals(Paper) ||
this.equals(Rock) && other.equals(Scissor);
}
}
class Round {
private Hand firstPlayersHand;
private Hand secondPlayersHand;
public void setFirstHand(Hand hand) {
this.firstPlayersHand = hand;
}
public void setSecondHand(Hand hand) {
this.firstPlayersHand = hand;
}
/**
* -1 if there's no winner 0 if it's a tie 1 if first player won or 2 if the second player won
* @return an int representing the outcome.
*/
public int getWinner() {
if(!isFinised()) return -1;
if(firstPlayersHand.equals(secondPlayersHand)) return 0;
return firstPlayersHand.isBetterThan(secondPlayersHand) ? 1 : 2;
}
public boolean isFinised() {
return firstPlayersHand != null && secondPlayersHand != null;
}
}
private String firstPlayer; // Should perhaps be an actual palyer object
private String secondPlayer;
private int bestOf;
private List<Round> rounds = new ArrayList<Round>();
public Battle(String firstPlayer, String secondPlayer, int bestOf) {
this.firstPlayer = firstPlayer;
this.secondPlayer = secondPlayer;
this.bestOf = bestOf;
}
public Round getCurrentRound() {
if(rounds.isEmpty()) return null;
return rounds.get(rounds.size());
}
public void startNewRound() {
rounds.add(new Round());
}
public String getWinner() {
int roundsWonByFirstPlayer = 0;
int roundsWonBySecondPlayer = 0;
for(Round round: rounds) {
if(round.getWinner() == 1) {
roundsWonByFirstPlayer++;
} else if(round.getWinner() == 2) {
roundsWonBySecondPlayer++;
}
if(roundsWonByFirstPlayer>=bestOf) {
return firstPlayer;
}
if(roundsWonBySecondPlayer>=bestOf) {
return secondPlayer;
}
}
return null;
}
}
if you add some observer stuff to it you should be able to get things working, simply ‘inspect’ the model on updates.