Naked Objects
Enriching object behavioursAccessing fields safely | |
In object-oriented programming it is considered good practice
always to access an internal variable through its
The following method from the public Booking actionCopyBooking() { Booking copiedBooking = (Booking) createInstance(Booking.class); copiedBooking.associateCustomer(getCustomer()); copiedBooking.setPickUp(getPickUp()); copiedBooking.setDropOff(getDropOff()); copiedBooking.setPaymentMethod(getPaymentMethod()); copiedBooking.setContactTelephone(getContactTelephone()); return copiedBooking; } Value objects and internal collections don't strictly need to be accessed via their accessor methods as they already take care of the notification and persistence issues. It is, however, good practice always to use the accessor as this provides consistency in your code.
|
|
Copyright (c) 2002 nakedobjects.org You may print this document for your own personal use, or you may copy it in electronic form for access within your organisation, provided this notice is preserved. |