JamesBwoii
- 71
- 0
Bacterius said:Hum. The HotelBooking class in your diagram has a line connecting it to the customer, so I was under the impression every hotel booking was associated with a customer (like it's associated with a room). If that was not the case and I misread, then yes you might have to invert the logic a little bit (for instance if instead of bookings holding customers you have customers holding bookings, then instead of booking.getCustomer() you'd want customer.getBooking() and so forth). Either way the diagram is indeed missing something since you have a relationship between Customer and HotelBooking yet neither have methods that interact with the other (i.e. in the calculateBill() method, how is the billing system to know which customer is associated with a given hotel booking? that is the problem you are having right now)
Sorry for the confusion, does that clear things up a bit?
Ah, I see. Ideally I'd like to follow my UML and connect it so that every hotel booking is connected with a customer.
I've looked back at my UML, which is slightly different from the last time I uploaded it, and can see that a the Customer class is associated to HotelBooking class with aggregation.
I've done some reading to find out how aggregation is implemented in Java and found this.
Code:
final class Car {
private Engine engine;
void setEngine(Engine engine) {
this.engine = engine;
}
void move() {
if (engine != null)
engine.work();
}
}
I've played around and can't seem to it so this line works though.
Code:
Discount discount = booking.getCustomer().getDiscount();
Any tips would be fantastic! :D