Suppose I want to represent an apartment building in terms of floors and rooms with a single data object. Each floor has the same number of rooms at any given time. During the course of the program, I will need to change the number of floors occasionally and will need to change the number of rooms on each floor occasionally. (Don't worry about the building permits needed to do this.) Now, I also want to be able to iterate over either each floor (think "row") or each room (think "column"). For example, I might want to program the equivalent of "Johnson, go fix all the front doors on the 8th floor" or the equivalent of "Johnson, go fix all the front doors to room B on each floor". (Yeah, I know, for the latter I could iterate over each floor and then access room B but that doesn't feel as "clean" as being able to iterate over a separate room/column.) Does Anyone have any recommendations about how to approach this problem?
2 Replies - 252 Views - Last Post: 31 July 2014 - 08:46 AM
Replies To: Recommendations for iterating over either row or column?
Re: Recommendations for iterating over either row or column?
Posted 31 July 2014 - 06:59 AM
It is not a "row and column" issue, but one of collections and objects. You would have a room object. You would have a 'floor' object that would have a collection of 'room' objects. You would then have a 'building' object that has a collection of 'floor' objects.
Page 1 of 1