🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java
Article #378

Refactoring book + one to many implementation

#378
From: Andy Bulka
Date: Sat, 13 Nov 1999 00:00
35 lines
2314 bytes
I've just been using the "Change Unidirectional Association to
Bidirectional" on p199 of M. Fowler's Refactoring book.

Since the one-to-many relationship is so fundamental, I would expect much
interest in this refactoring/pattern.

I have however noticed that the example is incomplete: it shows an
addOrder() method but not a removeOrder() method.  Why is that?  Admittedly.
Fowler DOES show the code for a many-to-many relationship where both addXX()
and removeXX() methods are shown - which is elegant and fine by me.

So anyway, turning our attention back to the ONE-to-many (which ends up not
being so elegant, once you flesh it all out - that's my claim...)   I went
ahead and invented/implemented the 'missing' removeOrder() method  thus:

Class Customer ...
 void RemoveCustomer( Order arg ) {
  _orders.remove( arg )
  arg.Customer = nil
}

Notice I had to call
  _orders.remove( arg )
for this to work, which GOES AGAINST the basic idea of the 'controlling'
side of the relationship being the order class, not the customer class (see
his text)

So, with all due respect, is this the reason why fowler didn't show the
implementation of removeCustomer/removeXXX for the one-to-many refactoring
example?  I.e. it would have contradicted his idea of all the 'work' being
done by the controlling side?

-Andy Bulka
WindowWare Multimedia
Australia
Technical Details
Message-ID: <80hvjs$1pqi$1@otis.netspace.net.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114809,da48a4987570047e
X-Google-Attributes: gid114809,public
X-Google-Thread: 10d6db,da48a4987570047e
X-Google-Attributes: gid10d6db,public
X-Google-Thread: f5d71,da48a4987570047e
X-Google-Attributes: gidf5d71,public
X-Google-Thread: fbe9c,da48a4987570047e
X-Google-Attributes: gidfbe9c,public
From: "Andy Bulka" <abulka@netspace.net.au>
Subject: Refactoring book + one to many implementation
Date: 1999/11/13
Message-ID: <80hvjs$1pqi$1@otis.netspace.net.au>
X-Deja-AN: 547895755
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
X-Complaints-To: abuse@netspace.net.au
X-Trace: otis.netspace.net.au 942440892 59218 210.15.250.20 (12 Nov 1999 21:08:12 GMT)
Organization: A customer of Netspace Internet
NNTP-Posting-Date: 12 Nov 1999 21:08:12 GMT
Newsgroups: comp.lang.java,aus.computers.java,borland.public.jbuilder.java,comp.lang.smalltalk