Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>How you deal with Rooms and Walls depends on the task at hand.</p> <p>I'll illustrate this with two examples, and then I'll get back to giving my answer to the actual "point" of your question.</p> <p>First Approach (Navigating a 1 story Building):</p> <p>Objective: I want to tell a Robot to move from its current location to the Copy Room.</p> <p>I determine the dimensions of the building, say 100 ft, by 100 ft. Choose an axis, and make a grid of points. The robot may start at location (50,50). Next, I create a <a href="http://en.wikipedia.org/wiki/Graph_%28abstract_data_type%29" rel="nofollow">Graph</a> where each edge represents one step to North, East, South, or West from that node to the corresponding node. Nodes separated by a wall have infinite weight, i.e. can't be passed through. </p> <p>The Graph is represented in an adjacency-list.</p> <p>Now I define a Room to be a polygon and list its verticies. To test if the robot is in the room, it must be within the area defined by the room's polygon. In this case rooms can overlap, especially since in real life standing in the doorway could mean you are in either room.</p> <p>My robot can now navigate the building, move furniture, and whatever else it wants to do.</p> <p>Second Approach: (Object Oriented)</p> <ul> <li>Building <ul> <li>Properties <ul> <li>Width, Length, Height, Geo-Spacial Coordinates, Age, etc.</li> </ul></li> <li>OuterWalls <ul> <li>may be BrickWall, GlassWall, ConcreteWall, etc inherited from OuterWall</li> <li>Properties: location, thickness, etc</li> <li>Methods: DemolishWall(), PaintExterior( Color C ), etc.</li> </ul></li> <li>InteriorWall <ul> <li>May be NorthSouthWall or EastWestWall.</li> <li>Properties: hasDoorway, N/E color, S/W color, etc.</li> </ul></li> <li>Room <ul> <li>Properties: Name, Location, Width, Length, etc.</li> </ul></li> </ul></li> </ul> <p>Notice that in neither of these examples do the rooms directly refer to their walls. </p> <p>Now to the actual point of your question. If two objects have a shared resource how should that be taken care of.</p> <p>Parallel programming deals with shared resources in a variety of different ways.</p> <ol> <li>Give each object a reference to the shared resource, make sure to synchronize or otherwise deal with concurrent behavior on the shared resource.</li> <li>Make the shared resource available to each object as a global variable or through a singleton object, or a static resource in another class, or even a specific location in memory or file system.</li> <li>Pass the shared resource between the concurrent parts in a predefined order or at predefined times.</li> </ol> <p>Imagine a hotel with a shared bathroom between each two rooms:</p> <pre><code>HotelGuest A = new HotelGuest( new BusinessMan() ); HotelGuest B = new HotelGuest( new Programmer() ); A.Room = 101; A.Bathroom = 7; A.BathroomKey = getBathroomKey(7); B.Room = 102; B.Bathroom = 7; B.BathroomKey = getBathroomKey(7); //Asynchronously A.RunDoBusinessStuff(); B.RunProgrammerStuff(); //but each has to lock bathroom7 when they use it, or it could be embarrassing. </code></pre> <p>But in the above example, how does the bathroom know which two HotelGuests have its key?</p> <ol> <li>create a database with the current guests and the keys they have, and the bathroom can query the database (or list).</li> <li>store references to A and B in the bathroom properties. (imagine a white-board in the bathroom listing its 'tenants').</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload