[OOP] Two classes that can acces each other's members

Started by
15 comments, last by Mussi 11 years, 8 months ago
Well, this is my second try to OOP design a game :P .I never would have thought this field is so complicated.
It seems I missed a lot.It would have never occured to me to try an idea like hstubb's one.
I guess I'll try for the moment Mussi's first suggestion.
Thanks for the time to reply :) .
Advertisement
Wouldnt it be worth experimenting with inheritance ?

Make a base class , say Entity ( controls all types of movable objects) , and have Player inherit this Entity class, and your Enemy inherit the class... so both are a Entity, and share the basic structure of an Entity but have special functions related to themselves.

I am not too comfortable with OOP myself, but that would be something I would experiment with as a attempt to see if it solves my issues.
You have some freedom in C++ that you shouldn't use if you want to follow correctly the OO paradigm. For example, suggestion A of Madhed said:
A. Make all members public[/quote]

This is very wrong. C++ allows you to do that, but you will create a strong relationship between A and B that may cause you greater problems in the future. Besides, those classes won't be easily reused throughout your code or other projects.

Try looking a little into OO basics and search for some Design Patterns like MVC first.
Programming is an art. Game programming is a masterpiece!
Thanks, I'll look at it .
I'm a beginner and only have experience with Java so far, but accessing another classes members should be as simple as creating a public method that returns the wanted information.

Maybe I don't understand the question properly.
I'm bumping because I wanted to show you my design for the game.
http://imgur.com/aez1h

The dots represent pointers .Order of declaring classes is bottom up .
Tell me , how bad is it ..
Your current design will quickly turn into spaghetti code if it hasn't already. I think you should start with reading this and then read up on some other OO design principles(hope someone else can provide some good resources, don't have any at hand).

This topic is closed to new replies.

Advertisement