The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Big Class,can it be redisgned?

Hi,
I am developing a web-based ASP.net 2.0 solution.In,admin part of application,the user has the facility to add information related to hotels like name,roomtypes,hotelseasons,roomrates and meal rates.
So,I designed these classes Hotel,which has a collection of following objects HotelSeason,RoomType,RoomRate,MealRate..and has methods ..addRoomrate,addSeason,addRoomType,addMealRate,addluxurytax and also methods which allow to change properties,and then there also validation methods.Hotel does not have any save,update or delete method.These actions are performed by a DAO object,which uses Nhibernate to do database related operation.
Now, I am begining to wonder,if Hotel has too many methods,how else I could handle this scenario? Though,I feel conceptually Hotel is the aggregate root,and all other entities are part of this root.
thks
vishy
Sunday, August 13, 2006
 
 
Why is addRoomRate() on the Hotel class?  Shouldn't it be on the class representing the collection of room rates?

Hint: Don't use the raw collection types to hold your business entities.  Always create type-safe collection classes -- whether by encapsulation, or by using generics.
Example Send private email
Sunday, August 13, 2006
 
 
Why would you ever have a collection of just room rates?
son of parnas
Sunday, August 13, 2006
 
 
Hmm.

  "I am developing a web-based ASP.net 2.0 solution.In,admin part of application,the user has the facility to add information related to hotels like name,roomtypes,hotelseasons,roomrates and meal rates.
So,I designed these classes Hotel,which has a collection of following objects HotelSeason,RoomType,RoomRate,MealRate..and has methods ..addRoomrate,addSeason,addRoomType,addMealRate,addluxurytax and also methods which allow to change properties,and then there also validation methods.Hotel does not have any save,update or delete method.These actions are performed by a DAO object,which uses Nhibernate to do database related operation.
Now, I am begining to wonder,if Hotel has too many methods,how else I could handle this scenario? Though,I feel conceptually Hotel is the aggregate root,and all other entities are part of this root.
thks "

Typical solutions to the 'Ball Of Mud' design is to try to identify entities inside the class.  Then, break out individual classes for each entity.  Then, add an 'has-a' instance (or list of instances) to the original 'big class'.

Hmm again.  You say "class Hotel, which has a collection of Objects".  Do you mean Hotel actually has a Collection of Objects?  Because having different 'addXYZ' calls for every type is a typical error.  Instead you'd have a 'base' class, which had an 'add' method, and Room, Restaurant, HotelSeason, would instantiate that 'add' method as appropriate.

Also, RoomType sounds like it should be a property of Room.  RoomRate also a property of Room.

So, in this design, Hotel would have a property, HotelContents, which would be a list of the things the Hotel could contain.

Then, when you instantiate each Hotel object, you add 'Room' objects to the list (by creating an instance and calling the Hotel's single "addPiece" method).  You add a 'Restaurant' object similarly, calling the same "addPiece" method.

That's one suggestion, anyway.
AllanL5
Sunday, August 13, 2006
 
 
"Hotel does not have any save,update or delete method"

So what class does?  Would it make sense to move the methods there?  It's hard to answer any questions with the little concrete info you've provided.
bmm6o Send private email
Sunday, August 13, 2006
 
 
Rich Fuchs
Monday, August 14, 2006
 
 
>> Why would you ever have a collection of just room rates? <<

So when the manager is assigning a rate to a room, he'll have a list to pick from.
Example Send private email
Monday, August 14, 2006
 
 
Vishy, I believe you really don't understand object-oriented programming, or inheritence.  (Or, for that matter, standard English punctuation - a lack that makes your posts very confusing and unecessarily difficult to read.  I would refuse to work with, or hire, anyone with such bad writing skills, and such confusion about the basic principles of software design.)  However, you're willing to learn, and there might be someone else reading who could also benefit.  So, let's go through this as an exercise.

Tell me a story about who will use the system, and how they will use it.  (In UML, this is the collection of Use Case Scenarios.)  Have you stayed at a hotel?  What are the events that occur?

The Guest searches for rooms available at a particular night.

If the Guest finds an acceptable room, the Guest may make a reservation.  Reserved rooms may not be shown as available.

The Guest might need to make a deposit to hold the room.

If the Guest cancels the reservation early enough, the deposit is refundable.  Otherwise, there might be a cancellation fee, or a forfeiture of part or all of the deposit.  Upon cancellation, the room may be shown as available.

When the Guest arrives, he or she checks in.  If the guest does not arrive by latest check-in time, the room may be shown as available.

While the Guest is checked in, he or she might order a  meal.  I recommend leaving meals out of your version 1.  Just deal with rooms.  Add meals to version 2.

When the Guest checks out, he or she needs to pay a bill.

Also when the Guest checks out, housekeeping needs to prepare the room for the next traveller.  For simplicity, let's suppose that latest check out and earliest check in times are far enough apart to guarantee availability.  This is an operations matter that does not need to be included in the reservation system.

What activities does the hotel reservation system need to handle?

* Search for non-reserved rooms meeting criteria
* Make a reservation
* Cancel a reservation
* Check in
* Check out
* Turn around the room

What functions do you need to have?

Let's look just at the room search and reservation use cases.

From the stock of rooms, select non-reserved rooms meeting given criteria.  Display the stock to the traveller, showing pricing applicable to the season in which the traveller will visit.  Provide a "reserve this one" command.  Show confirmation of the reservation date, room, and room type, and capture payment information.  Process payment information, and provide a reservation receit.  Remove reserved rooms from the available stock.

What data model is needed for this to occur?

If the system can reserve more than one hotel, then there needs to be a Hotel table.

The system needs to know of Rooms in the Hotel.

Each Room needs to have a RoomType.

For each RoomType, there is a price for each Season.

Each Season has a starting date.

Reservations indicate the Room, ReservedDate, and Guest.

Start by being able to search for unreserved rooms, and reserve them.  Then work your way through the rest of the scenario:

* What data model is required to implement cancellations?  To have cancellations support a cancellation penalty based on the number of days away from the reserved date?  To bill the guest for cancellation?

And so on, through the scenario.
Flow
Monday, August 14, 2006
 
 
My complete model of the class is this..

I have a Hotel class..which has collection of Seasons(Season class),collection of Rooms(Room class),collection of MealRate.Room has a collection of Rates(with property like season)...So,Hotel is the aggregate root,and all manipulations are done through a refernce of Hotel object.
vishy
Tuesday, August 22, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz