Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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