Abstract class

I programmed a monopoly game and it all works fine, but now I need to implement classes. My tutor explained what I should do, that I should make an abstract base class called player( inside will have the symbol, money, an array of houses owned, an array for the board and the player location. Then 2 derived classes for human and computer.
?? My question is if I derive the two classes will they have their own values, cause I thought it would overwrite the information in the player class. ??? Another question is how would I tie the two classes together cause the human class needs to know the information in the computer class.

A nice thing about abstraction is that you can use it to define "skeletons" that you can use to build more complex classes.

A banker and a realtor are both people. You could use an abstract "person" class and create a "Banker" and "Realtor" class that inherits from your abstract "person" class. In your case, just two players.

Why does the human class need to know what's in the computer class? If one really needs to know about the other, you can do that in a number of ways. However, it becomes increasingly difficult to make multiple objects know about the properties of other objects.

When you derive from an abstract class, it doesn't overwrite the abstract class. Both of the derived classes would have a "person" as their foundation, and you build on top of it. They're like "people" but with added functionality.

Think about it this way: a Ferrari and Honda Civic are both cars.
You could create an abstract class "car skeleton". You can't actually use a car skeleton by itself, but you certainly can build from it! Honda Civic and Ferrari could be derived from the car skeleton class. They would both be car skeletons, but with added features that you can actually use.

It can get much more complex than that, but it's a more simple explanation. I don't want to flood you with intricacies.
Thank you! Trust me it helps, and the human needs to know what properties the computer owns, that's the biggest reason. So that's what has be stumped. I could post my code in an hour if you like.
Hmm. You could make another object that stores which properties are owned, and some sort of identifier, like a string, to tell which player owns it, that way you don't have to make the human class depend on the computer class. There are actually many ways to do this. You're more than welcome to post your code here.
Lol the program is way too long, even the smallest part. Sorry, but do you mind giving me an example on how to make 2 derived classes from an abstract base class. With another class (as you said that holds the properties owned).
Just something simple that i can build upon.
Topic archived. No new replies allowed.