• Advertisement
Sign in to follow this  

Multiple classes question, yay or nay

This topic is 1601 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

I'm pretty new to developing (started with Game Maker last year, Unity with JS this year and C# with XNA last week sometime) and I was just wondering, if I made a game would it be easier to give each object its own class then set their own functions in those classes then call them in the main class, or would this cause problems later on down the line?

Share this post


Link to post
Share on other sites
Advertisement

The exact answer to this question depends on what you want to do and should become clearer as you become more familiar with object-oriented programming.

 

Generally, 10,000 foot view: you can think of classes as blueprints for objects, and objects as concrete instances of classes. You will run into situations where, from some classes you only make one or two objects because you do not need more (example: ItemFactory), and from some other classes you make many thousands of objects (example: Item).

 

You do not generally want to call into every single object from the same main method, instead you create some objects and call into them, and they might have some other objects in their variables and they will work on those, and those objects might be composed of other objects who they can call as needed, etc, etc. 

 

I think the best thing you can do right now, if you want to stick to C# and XNA (which is a good choice for a game programming language and platform IMHO), is read a book about general object oriented programming written specifically for C#. Things will then very quickly become much clearer.

Share this post


Link to post
Share on other sites

The exact answer to this question depends on what you want to do and should become clearer as you become more familiar with object-oriented programming.

 

Generally, 10,000 foot view: you can think of classes as blueprints for objects, and objects as concrete instances of classes. You will run into situations where, from some classes you only make one or two objects because you do not need more (example: ItemFactory), and from some other classes you make many thousands of objects (example: Item).

 

You do not generally want to call into every single object from the same main method, instead you create some objects and call into them, and they might have some other objects in their variables and they will work on those, and those objects might be composed of other objects who they can call as needed, etc, etc. 

 

I think the best thing you can do right now, if you want to stick to C# and XNA (which is a good choice for a game programming language and platform IMHO), is read a book about general object oriented programming written specifically for C#. Things will then very quickly become much clearer.

Thanks man! Have you got any recommendations on good books to study with?

Share this post


Link to post
Share on other sites

I'm more of a Java guy and not that closely familiar with C#. I have not read any C# books but I think the C# Yellow Book might be worth a look to start with. It's a university level text, it's supposedly written for people with no programming experience, the latest update was just last year, and you can't argue with the fact that it's free cool.png

Edited by stanirya

Share this post


Link to post
Share on other sites

I read the yellow book it was ok as an introduction (although I read it to get myself up to speed with C# and already knew C and C++). Bloke who wrote it thinks himself hilarious though, I bet he wears "groovy" ties ;)

Share this post


Link to post
Share on other sites
Besides" yes you should create a class for each object" I can hand a more practical answer.

For a game like pong you need a paddle and ball class. The behavior of these "objects" is programmed in these classes. When a player caims a paddle it will give control for it otherwise it takes your ai. When you need multiple balls you just create another object from the ball class.

Fot each object in the real world you would create a class. Take a car for example. The car would be a class it could be very practical to create a class for the wheels too since you have a lot of different wheels and it could hold things like wearing and presure too. The car class should ave access to the wheel class.

Using many classes gives you a lot more control over your program. If there is a problem with a certain part it is easy to look up.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement