R
Richard Turner
Hi,
I'm new to Ruby, so I'm still learning the Ruby Way. I'm also reading
Martin Fowler's 'Refactoring' at the moment and have realised that some
of the classes I've created in a program I'm writing fit his description
of value objects that should be refactored into reference objects.
Those classes are, in fact, wrappers over entities in a DB so I need a
factory (creation) method to always return the same object when given
the same creation parameter. E.g.:
Section.getSection(10) always returns the same object representing the
record in the DB with primary key '10'.
Since I can't make Section's constructor private in Ruby I wonder how
should I refactor my class into a reference object class? Indeed,
should I do this or does the Ruby Way use some other method?
Cheers,
Richard.
I'm new to Ruby, so I'm still learning the Ruby Way. I'm also reading
Martin Fowler's 'Refactoring' at the moment and have realised that some
of the classes I've created in a program I'm writing fit his description
of value objects that should be refactored into reference objects.
Those classes are, in fact, wrappers over entities in a DB so I need a
factory (creation) method to always return the same object when given
the same creation parameter. E.g.:
Section.getSection(10) always returns the same object representing the
record in the DB with primary key '10'.
Since I can't make Section's constructor private in Ruby I wonder how
should I refactor my class into a reference object class? Indeed,
should I do this or does the Ruby Way use some other method?
Cheers,
Richard.