Tag Info

Hot answers tagged

7

Note that there is nothing wrong with multiple inheritance. The diamond inheritance issue is... a problem. Plain multiple inheritance with no common bases is quite useful. That said, inheritance at all is generally the wrong approach unless you're implementing functional interfaces. Many class hierarchies, including your own, end up looking too much like ...


3

Dependency Injection is able to solve this problem. A top-level object, rather than implementing or overriding a specific process, defines that it requires an object capable of fulfilling it. It also defines what that object is supposed to do, i.e. it defines the component's interface. Then smaller, simpler, and independently implemented objects must ...


3

The problem seems to be that if i create a list of Tweens, then call update, it uses Tweens implementation of Tween.update() and not it's inherited children, I don't know how/if it's possible to allow this... Of course it's possible, that's the whole idea of polymorphism. You just need to ensure two things: 1) Mark the Update method as virtual in your ...


2

You're doing it wrong. Making a class for each level? No, levels are data, not code. Make a generic Level class, and then load .level (or whatever) files into it. The files then should just have a list of all the resources that need to be loaded, a list of events/scripts, and so on. Why? Because then you can make a separate level editor, that creates the ...


2

If by "if the final waypoint is reached, then do class specific action" you mean just calling the "endFunction" then yes, polymorphism will do the rest. That is, if you implement "endFunction" in every subclass or have a default one in the superclass.


2

First of all, CEntity should not have an Intersect method at all. This is simply not its functionality, in your case you are going towards a god CEntity class that knows about everything, when you should usually prefer minimal interface. When designing a class I always strive for these two principles; Single Responsibility Principle Liskov Substitution ...


1

C++ is powerful, but it's verbose. If what you want is lots of small polymorphic classes that are all different, then yes, it's going to take lots of source code to declare and define. There's nothing to do about it, really. Now, as ltjax said, what you're doing here isn't exactly polymorphism, at least for the code you've provided. I can't see a common ...


1

I would look into component design http://gameprogrammingpatterns.com/component.html http://www.gamasutra.com/blogs/MeganFox/20101208/88590/Game_Engines_101_The_EntityComponent_Model.php It uses wrapper classes and loads them with reusable components. This has several advantages. First is "flattens" out an inheritance tree. Say you have a vehicle ...


1

It really sounds to me like you want to use multiple inheritance to mix together different pockets of functionality to form something new. While dependency injection can be useful in an inheritance hierarchy, a better option would be to form aggregate object compositions. Using a component based architecture is a simple and natural way to piece together ...


1

Your entities need ID's in some form or another, if you want to persist them to disk, or pass them over a network. Thus, what you probably want is not to get rid of ID's, but to dynamically generate them so you don't have to set them manually in the code every time you create a new Entity-class. I've done this in my latest C# project by creating a special ...


1

I use IDs (for entities, not components), though I could do without them if I didn't want weak referencing for purposes of persistence + lazy loading. Mine do not defeat polymorphism as you describe, though. Try having your IDs provided by a universal registry and accessed via a standard interface.



Only top voted, non community-wiki answers of a minimum length are eligible