Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Quick question on OOP

Name: Anonymous 2012-03-26 21:14

Hey guys, just a quick question here...
Current making a game in C# (herp derp, yeah... it's a requirement for the course I'm studying) and I've got what I want working so far.
But as for the OOP, I'd just like something clarified. I've made a class for a tiled map, but I also have quite a few variables/objects in the main game class that I'd like to access from the map class. At the moment, I've just made all of these public and it works fine. But it seems to me like this is a bad way of doing it... Just doesn't feel very correct.

I was thinking of making a new class that just contains everything I need (kind of like an interface between the two classes) but that also seems kinda stupid.

So yeah, if anyone understands what I'm asking... What exactly is it that I should be doing here?

Name: Anonymous 2012-03-26 22:05

Why are you trying to do OOP when you have no clue how it works? Learn the basics first. Seriously, you'd do yourself a favour.
Go read some good book. Actually, go read Code Complete.

Name: Anonymous 2012-03-26 22:07

Part of the idea of OOP is that all relevant properties have a conatining scope wherein they are most important and relevant and only go outside of that scope when called.

If you have a large group of properties that are constantly interacting and at the moment they're broken up into various scopes that don't/wouldn't lend themselves to communicating with each other, then you may need to redefine your Class hierarchy or the fundamental structure of your program.

Name: Anonymous 2012-03-26 23:16

Pretty much what >>3-kun said.

In another words, your STUFF inside a class should have as much communication inside it as possible - that's called having high cohesion. You can check quickly what kinds of cohesion do exist and compare them with your code using the lame wikipedia link http://en.wikipedia.org/wiki/Cohesion_(computer_science) .

BUT, at the same time, your STUFF should have as FEW communications with OTHER classes/modules as possible. That's called having "low coupling". Check http://en.wikipedia.org/wiki/Coupling_(computer_science) for a quick reference.

Try to rethink how they are working. C# is a nice LANGUAGE to learn some of that stuff - the .NET FW is a pile of shit. So you'll have a fun time refactoring it.

If you noticed something looks cheesy, you may take even less time figuring out.

Name: Anonymous 2012-03-26 23:39

>>4
That's brilliant, thanks a lot! Have heard of coupling and cohesion before, but I'll make sure I understand them properly now. Think I'm going to try making a single class that just contains all the properties that I'm trying to access, and have all the much-used public variables/objects in there for now... Not sure why I didn't think of it before, but I think it's an okay solution.

Don't change these.
Name: Email:
Entire Thread Thread List