Questions tagged [polymorphism]
The polymorphism tag has no summary.
26 questions
0
votes
1
answer
108
views
Newtonsoft.Json JsonConvert.DeserializeObject (Polymorphism)
I'm using JsonConvert.DeserializeObject to deserialize animals from the Animal list, but unfortunately they get deserialized as Animals instead of their derived classes (Cat and Dog). As you can see, ...
2
votes
1
answer
426
views
What design pattern should I use for adding functionality
I am making a tile based roguelike game with different objects in the world, like Doors, Security Cameras, Storage Shelves.
With that, there are objects that have an inventory, can detect the player, ...
0
votes
0
answers
82
views
How to handle collision detection with different 2D shapes while maintaining performance? Is polymorphism appropriate?
If I'm making a small library for handling 2D shapes, should polymorphism generally be avoided? I know that it can worsen performance but it's not like polymorphism is never used in game development ...
0
votes
2
answers
249
views
How to replace if/else/switch with polymorphisim
For a long time Robert Martin has been advising against if/else/switch branching logic and instead rely on the polymorphic behavior of different types. ...
0
votes
1
answer
72
views
Problem with Parameters for polymorphism class
This is going to be a bit tricky but it is really bothering me so I hope you will have the patience to follow along :)
Here is my very basic architecture:
So in the framework, I am creating I have <...
0
votes
0
answers
87
views
is there any different solution for different buildings different behaviours
I'm trying to make different behaviours for workers of different buildings, let's say an agricultural worker would need to sow wheat seed and collect the wheat grain when it's grown. let's call that <...
0
votes
0
answers
174
views
Remove nested if statements
I have been learning a new method of programming. I have been programming many years and am recently finding out there is a better method in general via abstract classes.
My question is how to ...
0
votes
1
answer
113
views
Interact with inheriting class methods from "casted" base class (collisions, etc)
I want to implement a damage system that works across both living items (Entity) and environment items (Environment). The key ...
1
vote
1
answer
1k
views
RPG Item Design [duplicate]
I'm currently fiddling around with some RPG mechanics and I'm trying to implement a solid way to handle items that have different on use effects.
Currently, I have a base class called "Item" that ...
3
votes
2
answers
1k
views
Using polymorphism in an Entity-Component System without sacrificing data-oriented design
I've been planning out an Entity-Component System in C++. My idea of it is most in line with the one described on this page of the entity systems wiki. To summarize, components are just structs of ...
0
votes
2
answers
268
views
How to: Duplicating and updating component data in systems
I am new to game development. Coming across the ECS (entity-component system) pattern I generally quite liked the idea. I have implemented the current version of my engine using the OOP style approach....
0
votes
1
answer
1k
views
Make the components of an ECS polymorphic
I have implemented an entity component sytsem (ECS) in my game engine (SFML and C++ 17). An entity has an array of components. You can get a components by its type e.g.: ...
1
vote
1
answer
453
views
Component based Entity System using polymorphism: OpenGL does not render
I want to be able to create Entities from different Component sets. I want to call Entity entity(new StaticObject(modelpath, position));
I have an EntityTypes ...
2
votes
2
answers
253
views
Cost of Using Virtual Methods to Query Properties?
Let's say you're making a tile-based roll-playing game, and you're obsessed with OOP.
You have an abstract base class Tile which will be inherited from by many ...
1
vote
1
answer
460
views
Inherited property in derived class reference only base class
[Context] I am developing a game in Unity, and wanted to make a Game Manager. Like many examples out there, it uses a Singletron design pattern. But i have several other Managers, all using Singletron ...