Home > Archive > Smalltalk > April 2006 > Your opinion: is it better to extend or to add?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Your opinion: is it better to extend or to add?
|
|
| Thomas Gagne 2006-04-18, 10:03 pm |
| In VW's WsdlClient class, there's an instance method #loadFrom: which
takes a URI as a parameter. It's used as:
aWsdlClient loadFrom:
'http://services.xmltoday.com/vx_engine/wsdl.vep?joke.wsdl' asURI.
It seems the code would read better if it were just:
aWsdlClient loadFrom:
'http://services.xmltoday.com/vx_engine/wsdl.vep?joke.wsdl'.
especially if I were to show the code to non-Smalltalkers.
One option would be to add a new #loadFromString:
aWsdlClient loadFromString:
'http://services.xmltoday.com/vx_engine/wsdl.vep?joke.wsdl'.
another would be to modify #loadFrom: to send #asURI to its parameter so
it wouldn't matter if a URI or String were passed.
My first thought was adding #loadFromString: would be cleaner in that it
wouldn't be necessary to modify #loadFrom:'s code. But adding
#loadFromString:, when #loadFrom: already exists makes Smalltalk look
more like a static language than a dynamic one. A different method for
each parameter type? I'm I way out on this one?
| |
| Runar Jordahl 2006-04-19, 7:06 pm |
| If you were the author of the class WsdlClient, I would recommend that you
changed the original method. I would then name the method and its parameter
like this:
loadFrom: aStringOrAnURI
But as you say, WsdlClient is not under your control, so you have (among
others) these two choices: Add a new, extended method, or modify the
existing one. In general, I try to avoid modifying classes and frameworks I
do not control. Doing such modifications can lead to conflicts with other
code using the component, and makes upgrading to new versions of the
modified component harder. So in your case, I would simply make a new
extension.
If you however choose to modify the original method, Store has a concept of
"overrides" to help you manage such changes.
Runar Jordahl
|
|
|
|
|