List of generic objects

Started by
10 comments, last by Pink Horror 9 years, 7 months ago

Don't take this the wrong way, but TBH, this whole concept is a bit messy.


I'm just working with what I've got. I don't time to refactor his entire project so I'm just showing him ways to solve his immediate goals with the minimum amount of redesign.


Sorry Nypyren, that wasn't aimed at you. Your solution is absolutely workable in the immediate case, I was speaking more generally.

The sections you highlighted are base classes which take advantage of polymorphism... which I think is different from generics.


Sorry, but that's completely incorrect. To go through each case


public List<Creature> critters = new List<Creature>(); // Generics!

This is a generic list of Creature object (implemented as a vector). There is no polymorphism here.


Func<Unit,Creature> m_creationDelegate; // also generic

A generic delegate, essentially a typed function pointer. Again, no polymorphism.

As for your hierarchy, you should favour composition over inheritance, especially in a language like C# that doesn't allow multiple inheritance. Your Human object can expose IPhysical, IActor, ICreature, etc., interfaces but it would be better implemented using components.

I wouldn't go as far as Sean as to say you shouldn't model concepts as objects (certainly not for a small project) but still you have a lot of inheritance and that should be ringing alarms bells.

if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
Advertisement

Sorry, but that's completely incorrect. To go through each case
public List critters = new List(); // Generics!
This is a generic list of Creature object (implemented as a vector). There is no polymorphism here.

The OP isn't storing plain Creatures in the Unit class, though, he's storing Goblins or Trolls, and overriding virtual methods on the Creature class. Using a List of Creatures for storing and manipulating Goblins or Trolls is taking advantage of a common super class, which is taking advantage of polymorphism.

Also, generics are just a different form of polymorphism.

This topic is closed to new replies.

Advertisement