In an OOP design phase strategy,
Any physical/conceptual object of a system can be modeled(considered) as computational object in your OOP designed program based on below two conditions:
First case: That physical/conceptual object of a system must have it's local state and that state changes over time.
or
Second case: that physical/conceptual object of a system may or may not have it's local state but that same object must influence the state of other physical/conceptual object of a system through interactions.
Above two cases are also supported here, which says: Viewing objects as finite state machines
To illustrate above two cases, below is the object model
diagram and class diagram
of coin flipping game.
class Coin
and class Player
type objects, have local state coinOption
, as mentioned in first case. class CoinGame
type object has no local state but influence the state of other objects(of type Player
and Coin
), as mentioned in second case.
As per second case, class CoinGame
type object influences the state of other objects of type Player
and Coin
through below interactions, but class CoinGame
type object itself does not have local state on it's own.
So, class CoinGame
does not maintain any local state and has composite
relation with Player
and Coin
, as per below java code.
public class CoinGame {
Player[] players = new Player[2];
Coin theCoin = new Coin();
CoinGame(String player1Name, String player2Name){
players[0] = new Player(player1Name);
players[1] = new Player(player2Name);
}
.....
}
Here is the complete code in java. Above two cases are valid, when you select objects from real world. Is my understanding correct?