Modelling points on a surface?

I'm not sure why adding an extra attribute is an efficiency problem - it won't affect the speed and it'll only increase the size of the object by 10 bytes or so. So unless you are dealing with millions of Agents (Missterrr Annnderssssonnn) I wouldn't worry about it You could alternatively have a single Surface which is created in a module as a local and accessed via a module method (a bit cleaner than a global). So something like: import TheSurface class Agent: ... def Move(self,x,y): surface = TheSurface.getSurface() surface.

CanIMoveTo(x,y) TheSurface. Py would have some kind of initialisation method that created the surface, which would need to be called at program start. @DesignPattern people: is this a 'singleton' pattern?

Creating an Agent with a Surface and storing it as an attribute is a better way. I don't see why you'd add it to a Point though The structure is something like: An Agent is on a Surface An Agent is at a Point Hence you can deduce that the Point is on the Surface, and there's no need to model that separately, unless perhaps you might be dealing with Points that aren't involved in some way to Agents, but then you will have the context of a Surface anyway. It'll always be "Right, now I have to put some Trees on this surface - createTree(surface,point)" etc.Anything on the surface has a surface and a point.

I'm not sure why adding an extra attribute is an efficiency problem - it won't affect the speed and it'll only increase the size of the object by 10 bytes or so. So unless you are dealing with millions of Agents (Missterrr Annnderssssonnn) I wouldn't worry about it. You could alternatively have a single Surface which is created in a module as a local and accessed via a module method (a bit cleaner than a global).

So something like: import TheSurface class Agent: ... def Move(self,x,y): surface = TheSurface.getSurface() surface. CanIMoveTo(x,y) .... TheSurface. Py would have some kind of initialisation method that created the surface, which would need to be called at program start.

@DesignPattern people: is this a 'singleton' pattern? Creating an Agent with a Surface and storing it as an attribute is a better way. I don't see why you'd add it to a Point though.

The structure is something like: An Agent is on a Surface An Agent is at a Point Hence you can deduce that the Point is on the Surface, and there's no need to model that separately, unless perhaps you might be dealing with Points that aren't involved in some way to Agents, but then you will have the context of a Surface anyway. It'll always be "Right, now I have to put some Trees on this surface - createTree(surface,point)" etc. Anything on the surface has a surface and a point.

Yeah that's a singleton -- but I don't see the point of making a singleton here. – senderle Jan 31 at 8:56 True. Just create the Agent with a Surface object.

The OP didn't want to add a Surface attribute to Point, so I've not added a Surface attribute to Agent. It would be the better way. I'll emend... – Spacedman Jan 31 at 9:01 Thanks for the answer.

I have a related question, but it's too big to put in comments, so it's here: stackoverflow. Com/questions/4860686/…. – max Feb 1 at 9:09.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions