Eamon Nixon wrote:The hotel system is similar. However the customer essentially takes a room Type= Single and a date=12/12/12 to the desk similar to the book scenario above. Where do I send this information to check that its Ok and get a room number?
John McClellan wrote:In a way you're thinking of it in excessively technical terms. Don't. You're also trying to copycat over from a different (thought slightly similar) problem. Don't.
Basically the whole idea behind using objects is to be able to model the problem in your code instinctively and naturally, much like it is in the natural world. If you're trying to come up with a class model or something in some really technical way for a very simple, natural problem like this, then you're not thinking about objects instinctively and naturally enough.
As for trying to pull from a library example, doing stuff like that is really more for learning a language or an API or something; it isn't something you want to do very much when going from one problem space to another. Admittedly it can be a good idea sometimes, but imagine the difference in the real world between checking out a book in a library and renting a room at a hotel. They're a little bit similar, but still pretty different. So in the real world, if you managed a library and started managing a hotel, you might take a few good ideas with you, but you wouldn't want to get too obsessed with using a really similar technique. Kind of the same idea here.
Eamon Nixon wrote:I am confused now about 2 things above.
1) A reserve agent class gets a request for booking these dates from a customer, 10/11/12 , 11/12/12, 12/12/12 for a double room. It sends a message to rooms class, please return all double room numbers(201,202,203 etc). Now it sends room booking class the (dates and all double room numbers) to see what rooms are booked for those dates?
When the message(return double rooms) is sent to rooms and there are 20 double rooms in the hotel, will there be 20 room objects created? or just 1 room object, then checked for availability on room booking class, destroyed if not available and another room object created and checked for availability, destroyed if not available and so on until an available room is found and returned to reserveAgent class.
Campbell Ritchie wrote:Welcome to the Ranch
You should be learning Java and design in parallel. You cant do advanced Java without something to program and you cant program anything unless you have designed it.
I agree with John McClellan that you are over thinking this problem. You should develop it incrementally. Designing it in terms of sending a message to find which rooms are available” is not part of the basic design, but an implementation detail, which you can work out later. Getting a list of available rooms is not necessarily part of the booking process. Getting, “Yes, we can accommodate four people from 18th July until 21st July is.
Stop thinking in terms of programming. think how you would model a reservation for a particular room from 18th to 21st July on paper. Then think how that can be programmed. The more you do on paper, the easier the programming task will be.
Start with a room, and decided what its attributes are. Probably number of beds and some way of relating the guest to dates. You may not need any more for a room at this stage. Get that working. Then adding the rooms to make up a hotel is an enhancement of what you already have. Remember number of rooms is an attribute of a hotel. You can have hotels with 25 rooms or 250 rooms.
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailbosshttps://www.kickstarter.com/projects/paulwheaton/free-heat