Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


CramerFish

Member Since 20 Nov 2012
Offline Last Active Jan 25 2013 06:19 AM

Topics I've Started

Pointers to an instance's owner

20 November 2012 - 08:31 PM

I have a question about the following design
class Unit {
  Manager *my_manager;
  ...
};

class Manager {
  vector<Unit> unit_list;
  ...
};
In the interest of encapsulation the Unit handles it's own actions (e.g. movement), the pointer to the manager is then required so that the unit can interact with other units (e.g. colliding). It feels like it's a hack, I've added in the pointer in the absence of a better design strategy. Is this an intelligent way to structure my code, or should I be looking for a different design pattern?

I'm from a Maths/Science background and so while I have done quite a bit of programming (FEM, graph theory, simulations) I haven't formally learned application programming. If there is a good book on how to design/structure a program that is more than just datain->process->dataout I would love to hear your recommendations.

PARTNERS