I think I miss some concepts of the OOP programming, but I don't know what exactly.
How Can I use the objects created from different classes?
For example, let's say I have to work with cards. There is a Card class, it contains all the shared properties. Normal cards and joker cards are inherited from the Card class (joker can take over any card color) and the a card can worth nothing or worth points, so there is a ScoreCard inherited from NormalCard.
So how can I use this model when I'm programming? I create N card in an array and when generating cards should I decide whether the actual card is a Joker/Score/Normal Card? And later how can I test if a card is a joker/normal/score card? Because if the ScoreCard
have a private int score;
and setters/getters the NormalCard
is not going to have this property, so when I write an if statement I don't know what to test.
Card[] cardsArray = new Card[52];
for (int i = 0; i<cardsArray.length;i++) {
//Some source tells if a card is a Score/Normal/Joker
String src;
switch (src) {
case "Joker":Card[i] = new JokerCard();
break;
case "Normal":Card[i] = new NormalCard();
.... etc
}
}
//Some Userevent:
..userevent(Card in) {
//Test what
if (in.value == 4) {
this.user.setScore(this.user.getScore()+in.score);
}
}