Am I thinking right OO way?

Started by
66 comments, last by oleksiy 13 years, 1 month ago

As stated, I refuse to argue the matter further, why beat a dead horse? Do you really think it's a mature thing to do? Do you really believe it's mature to claim some one is acting the victim? Your hostility, name calling, and sarcasm have been completely unwarranted. Get off your high horse, recognize that I have made SOME valid points and A LOT of not so valid ones. The user above you succeeds the the fact that when deciding whether something IS-A or HAS-A is completely subjective (although usually obvious). There's no reason for you to be so obtuse. If you can't handle a mature debate, don't participate in one. It's easy to debate. Assert your opinion, provide evidence to support your opinion and provide couter points to the other's arguments. Difference of opinion != hostile intent. ^^


If you refuse to argue the matter further why are you still replying to posts ?

Looking through through the posts i only see one poster who doesn't handle a mature debate very well and who has effectivly derailed this thread.

While it is true that the distinction between "is a" and "has a" can be muddy it usually isn't.

you might get away with arguing that this is a good design

class Person {
....
}
class Developer: public Person {
....
}

While it is true that a developer is a person something like:

class Occupation {
....
}
class Developer: public Occupation {
....
}
class Person {
private:
std::vector<Occupation> occupations
......
}

would be a better option since it moves generic occupation information out of the Person class (an unemployed person doesn't need those) and you could give a person multiple occupations (By adding work hours to the Occupation base class this design would allow you to easily create for example a student who works at 7-11 on friday and saturday nights while with the inheritance approach you'd have to create a new subclass for each combination).

Basically composition is more flexible than inheritance so if you're in a position where you can choose between them the composition route is almost always better.
(One can ofcourse take it further and cut out the inheritance for the Occupation class aswell and compose the Occupation class using things like job titles, tasks, etc which would make things even more flexible)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Advertisement
Wow! its been a while since I last seen a troll get this much attention.

Disregarding the troll under the bridge and addressing the concerns of the poor guy that posted this thread in the first place and went sort of neglected...

A lot of remarks on what is and what is not overkill have been posted, not just in this thread, however being this a post in "for beginners" and asking about the specifics of the object oriented philosophy I think it is best for the creator to learn the formal definitions first and then decide whether or not they fit the needs of his project, doing a simple game the complex formal way is not a waste if its purpose is learning.

As for the proper way I completely agree with Ravyne, the player and the AI are not paddles, they control the paddle, they have a paddle. Using inheritance in this case would be a "seems harmless now" mistake, stating that you need to expose the paddle member outside of player if you don't use inheritance in order to control its movement implies that the player is meant to keep score but does not know how to give orders to the paddle, which is just ridiculous, the player should handle input recognition for the specific needs of the paddle directly.

Also kaktusas2598 posted a concern for whether or not a game class is needed and then stated he would use an enum to represent current game state, as long as we are learning allow me to submit to you this technique: http://wiki.gamedev.net/index.php/Managing_game_state
It proposes a simple implementation with a lot of room to expansion but with a solid foundation in separating radically different state logics in a reusable way.
As for the game class, I would like to know which platform / framework are you using in order to recommend whether or not such a class is necessary, but with the current information I would advice in favor of its use.


Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272


Reasoning:

I propose solution X.

Another user says X can't be true but Y can because of principle P.

If I can prove the principle P is implemented subjectively, then I can effectively determine:

X == Y due to the subjective nature of the principle

This makes me a troll.... how? If you want me to stop posting, stop fucking attacking me. Ignore me. No one can relinquish control. You can argue with me, WITH OUT REFERRING TO ME. With out saying things like, Slynks a troll and why can't he stop posting. The fact that you keep making personal attacks at me means, you want to get under my skin. <.> Which makes you worse than me unfortunately. Also, notice that this post is not one of my opinion, but of WHY I was arguing so please don't respond with "Yeah will it's not subjective bla bla bla" I'm tired of the immaturity. I just wanted to try and prove the point above but everyone just keeps restating the same thing over and over while attacking me.

I may a be a stubborn, sensitive idiot but at least I don't treat people like shit. : /

EDIT:
Want to know how to do it?

http://www.gamedev.n...ost__p__4781141

Notice he argued against my point BUT didn't attack me. I read that long before Hodgman responded. And guess what, I didn't reply to it... >.<

Reasoning:

I propose solution X.

Another user says X can't be true but Y can because of principle P.

If I can prove the principle P is implemented subjectively, then I can effectively determine:

X == Y due to the subjective nature of the principle



My reasoning:

Your principle, P (the has-a/is-a implementation choices) may be subjective, but they have objective pros and cons.

As I, and others, have said many times, the issue is this:

Composition: better maintainability, reuse, decoupling, and cohesion.
Inheritance: less code, but worse (all of the above)

These aren't opinions, they are direct results of the implementation. There are numerous examples of that in this thread.

Basically, the part you're right about is: "One can view the problem many ways".
However, the part that you're wrong is: "Since one can view the problem many ways, all implementations are equally effective".

Now the burden is on you to show how your inheritance example lends itself to equal (or better) code reuse, maintainability, cohesion and decoupling than composition.
I think this thread needs to be closed as it's going nowhere. You don't walk up to a building site and start telling builders there's an alternative way to lay bricks. True as it may be, it's useless because they have years of experience and know what works.
Yeap, you can close it ;)

Deltron Zero and Automator.


[quote name='BCullis' timestamp='1299084969' post='4781050']in the context of following good OO practices there is a right and wrong way to go about your design.


I'm purely stating my opinion that:

"[color="#1c2837"]composition should be preferred over inheritance whenever inheritance is unnecessary"

[color="#1c2837"]is an opinion and there for does not designate "Good practice" maybe "Preferred Practice" or "Industry Standard" but in my opinion, without *me* seeing a benefit of following the principle, it can't make for a "good" practice. That's just my opinion ^^
[/quote]

I want to have two paddles per player. Revise your solution.

Done yet? Well, I changed my mind, I want 3.

Like others have said, composition promotes code reuse in a more direct way than inheritance. Anything that makes a project easier to build upon is good practice. Anything that does absolutely nothing for your code but resolves a sense of "it seems better to me" is not. "Good practice" is a tangible thing with tangible benefits. What are the tangible benefits in your method?

Like others have said, composition promotes code reuse in a more direct way than inheritance. Anything that makes a project easier to build upon is good practice. Anything that does absolutely nothing for your code but resolves a sense of "it seems better to me" is not. "Good practice" is a tangible thing with tangible benefits. What are the tangible benefits in your method?

If there are no bugs, it could take less time to code. This is the far far edge best case scenario.

I feel like Slynk has never worked on a legacy code base. Even on individual projects I don't like making bad design choices because of how much pain they've caused me in the past

edit: I've also changed my mind on a couple individual projects that resulted in me completely rewriting a lot of code and ended up taking days instead of minutes in changes.
this thread helped me a lot. thanks people.
also, slynk, are you here to learn? if yes, firstly, learn how to accept criticism and suggestions.
None of the replies here were of rude nature; they were very polite and informative. Don't bring "my opinion" into the game. I'd prefer to hear from you the "why"s. Opinions are very vague and abstract. Reasons and examples are concrete and exhibitive.
This post considers re-usability and maintainability of your system in a longer run.
On the same subject. Would it be a good approach to build an interface (IGameEntity) with such methods as animation, motion updates, draw and then implement them in another class (GameEntity : IGameEntity with virtual methods for overriding in future) with members (compositions) such as rendering information (position, centre, angle, rotation, texture key in the map etc), state of an entity (alive, hp value etc) etc. and then, via inheritance do the following

PlayerShip : GameEntity, EnemyShip : GameEntity, Asteroid : GameEntity, etc ?
What's the difference between a skydiver and a golfer?
A golfer goes "[WHACK] ... Oh sh*t!". A skydiver goes "Oh sh*t! ... [WHACK]"

This topic is closed to new replies.

Advertisement