Is it bad to pass instances of objects between methods in a class? Or is there a better way of doing this?
public void game() {
Deck deck = new Deck();
shuffleDeck(deck);
}
public void changeCard(Deck deck) {
deck.replaceCard(deck);
}
Is it bad to pass instances of objects between methods in a class? Or is there a better way of doing this?
public void game() {
Deck deck = new Deck();
shuffleDeck(deck);
}
public void changeCard(Deck deck) {
deck.replaceCard(deck);
}
Well... passing class object would be quite difficult in java. On the other hand the in-build mechanism of passing value of the reference is very useful and we all do that daily.
Is Java "pass-by-reference" or "pass-by-value"?
Operating with objects is a main principle of Object Oriented Programming
and Java is object oriented.
Remember that you don't pass the whole object. You can imagine that as passing the instructions on how to find that object in memory.