• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

OO design or concept

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using a library system example to design a hotel reservation system. I can understand the concept or use case for the library system like this. Member takes book to desk to borrow book. Gives member number. The member object checks to see if the guy has fines or too many books already. If everything checks out, he borrows book. Thats fine, I understand the concept here. You have Member class, Book class and CopyOfBook class. Member sends message to copy, copy send message to Book.
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?
Like the book scenario above, I need to change Single+ 12/12/12 to a room number.
For example 12/12/12+single becomes Room 4. Reservation sends room 4 a message you are booked for 12/12/12. How does 12/12/12+single become Room 4?
The system needs to know
Single rooms available for that date, so it can give me room 4 to replace 12/12/12+Single and room 4 + date I need to proceed with a reservation.

OO concept difficulty
I have a hotel class with information on how many bedrooms, meeting rooms etc. I think I will only ever have one hotel object.
I have a room class which gives details about the rooms, double-single, room numbers. For rooms I can have 50 objects, one for each room.

I need a class with the responsibility for available Rooms. Rooms is not responsible for that and Hotel is not responsible for that. Is reservation responsible? That doesn't seem correct to have reservation responsible for available rooms.
I have 50 rooms in my hotel, so I can have 50 room objects. 25 Single, 25 double. I'm thinking databases, but I know my concept is wrong. So the only information I can get from room is a single or double room. I want a single room.
I'm sure you can easily see my confusion. Lol
But can you throw me an example or scenario which might ease my pain?
I simply dont see where to get an available room for a specific date and type from. Also, I'm not using a database, but I'm sure I should not be thinking databases when working out class models or interaction diagrams. Unfortunately, I dont yet understand objects. Trust me I have read about encapsulation, inheritance, interfaces etc, but the concept hasn't permeated the pygmy peanut yet.
Thanks for reading my rantings as I realise this is not Java specific.
Eamon
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

As for this example, I might or might not be able to come back and give you some advice - it kind of depends on things like time at the moment. But if I were you, I would build things up completely from scratch, come up with a design that way, and either see what happens or maybe post it and ask about it.
 
Sheriff
Posts: 28319
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?



I guess you don't remember how this worked in real life before the internet came along. Back in those days the customer would talk to a reservations agent who would take the particulars and produce a reservation.

(You don't necessarily have to reproduce the manual system when you write a computer-based version of the system -- that's what we used to call "paving the cow-paths" -- but for a first draft, or when you don't have a better idea, that's the way to go.)
 
Eamon Nixon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



I know you are right, but I think I'm trying to persuade myself that I have some understanding of the solution through the library example. This is entirely new territory for me as you can see. I need to let go of technical problems at this stage and just model the system based on real world responsibilities, roles and data. Is that a correct assumption?
I have used databases before and keep thinking about storing data and where to find data, this isn't helping, but hindering me.

As for the old world system, I do remember that and now I see the system a little better. As the old world system worked, you would call a hotel. Hotel class. A receptionist would answer, find an available room,Room and Reserve Agent class, ask me if I wish to proceed, then make a reservation for me. Reservation class.

As I would see this now,
Hotel class maintains hotel information, number and types of rooms.
Reserve Agent. Finds available rooms and makes reservations.
Room class. Maintains room data.
Reservation class. Maintains reservation data.
RoomBooking class, Maintains data about each room booking.

How does that look?

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.
2) If I have one reservation object for a customer, then I could have 10 related Room Booking objects as I can have many bookings for one reservation, so I would have NumRoomBookings=10 as an instance variable of reservation. I know this is getting too technical for class models, but I'm just curious.
Everything else above is simple and straightforward.Lol.

Thanks for your help guys also. Appreciated.

As an excuse for this thread, I dont only want to get to know Java in detail(although that would be great) without having some software design understanding also. I'm kinda hoping to step through some UML class models, interaction diagrams, use cases etc and Java at the same time. Any thoughts on this idea would be welcome also.
3) Do you think I should just concentrate on learning Java in more detail first and then consider design issues?
Lots of questions, maybe this should be a different thread?







 
Marshal
Posts: 79922
395
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
You should be learning Java and design in parallel. You can’t do advanced Java without something to program and you can’t 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.


Again, I suspect you're rushing to implementation a bit too soon. At the moment, you should be worried about what gets done, not how it gets done.

Take a reservation() function, for example: What actually happens?
Break it down in detail (and what, NOT how, remember). Your description should include things like required information (eg: dates, room size, name, CC details...), actors (the booking agent, the prospective client, possibly even the room itself), and results (eg: a reservation document, change of room status to "RESERVED", a note to cleaning staff...). A description of the actual steps involved is probably a good idea too, but write it in English, not in Java. Don't forget that it'll probably be part of a procedure document somewhere.

Once you know the what, you'll be in a much better position to determine the how; but it requires a lot more work up front before you start coding.

HIH

Winston
 
Eamon Nixon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



I think I know what you mean. On paper. A reservation should have a

1) Example
RESERVATION
reserveID ; reserveName ; Ccard ; CheckInDate ; CheckoutDate; NumRooms ; NumNights; TotalCost CheckedIn Checkedout
11 Eamon 2354 21st 23rd 1 2 150 No No

ReserveDetail
roomNum ; numGuests, GuestName ; Date ; roomType; Price ; ReserveID

3 2 J&N 21 Double 75 11
3 2 J&N 22 Double 75 11

ROOMBookings
RoomNum DatesBooked ReserveID
Room 3 21st July 11
Room 3 22nd July 11


The above example is fairly straightforward. 1 room booked for 2 nights.

But the reservation below is a little bit more complicated as it has 2 rooms booked for different durations. One room for one night and one room for 2 nights. I want to design a system which allows for multiple room bookings.


2) Example
RESERVATION
reserveID ; reserveName ; BookingCcard ; CheckInDate ; CheckoutDate; NumRooms ; NumNights; TotalCost
11 Eamon 2354 21st 23rd 2 3 200

ReserveDetails
roomNum ; numGuests, GuestName ; Date ; roomType; Price ; ReserveID CheckedIn Checkedout PaymentDetails

3 2 J&N 21 Double 75 11 No No
3 2 J&N 22 Double 75 11 No No
***********************************************************
2 1 Tom 22 Single 50 11 No No

ROOMBookings
RoomNum Date ReserveID
Room 3 21st July 11
Room 3 22nd July 11
Room 2 21st July 11

In this example, checkin would have to be with individual room rather than with reservation, room 3 and 2 are checkedIn. Also, you have the similar problem with checkedOut to Yes. Now, I have problems with payment. Perhaps J&N and Tom want to pay seperately.

Checking Out

2) Example
RESERVATION
reserveID ; reserveName ; BookingCcard ; CheckInDate ; CheckoutDate; NumRooms ; NumNights; TotalCost
11 Eamon 2354 21st 23rd 2 3 200

ReserveDetails
roomNum ; numGuests, GuestName ; Date ; roomType; Price ; ReserveID CheckedIn Checkedout Paid

3 2 J&N 21 Double 75 11 Yes No No
3 2 J&N 22 Double 75 11 Yes No No
***********************************************************
2 1 Tom 22 Single 50 11 Yes No No


J&N decide to checkout and only pay for their room.
PaymentDetails
roomNum ; GuestName ; Nights; roomType; Cost; ReserveID Checkedout Ccard Paid


3 J&N 2 Double 150 11 Yes 126 Yes
2 Tom 1 Single 50 11 No No

Now Tom arrives to checkout.

ReserveDetails
roomNum ; numGuests, GuestName ; Date ; roomType; Price ; ReserveID CheckedIn Checkedout Paid

3 2 J&N 21 Double 75 11 Yes Yes Yes
3 2 J&N 22 Double 75 11 Yes Yes Yes

***********************************************************
2 1 Tom 21 Single 50 11 Yes No No

PaymentDetails
roomNum ; GuestName ; Nights; roomType; Cost; ReserveID Checkedout Ccard Paid


2 Tom 1 Single 50 11 Yes 456 Yes

Is this what I should be doing with all my use cases. Make Reservation. check In, Check Out, Payment, Cancel Reservation. when I am finished my use cases, I will know WHAT I need to be able to do but not HOW to do it.

What data it needs to complete each use case?
NOT
HOW to complete the use cases.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a few steps that are needed before starting object-oriented design activity. Many of the posts in this thread are touching upon them in one way or another. Below is the J2EE-based standard approach published by Sun Microsystems.

Use Cases (Narratives and Diagrams)

Business Requirements (based on the Use Cases)

Technical Requirements (based on the Business Requirements)

Object-oriented design (based on the Technical Requirements)

Non-Technical Requirements

Architecture design (based on Non-Technical Requirements)

 
Alas, poor Yorick, he knew this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic