logo       

Re: A Question of Style: msg#00167

Subject: Re: A Question of Style
On Fri, 30 Mar 2007 18:22:22 +0200, Tim Johnson wrote:

Hi,

I know the rules for naming accessor and setter methods. But what do I do
when the accessor method needs a parameter?  I'll try to provide an
example.

A vendor sells an item called #apple. If I want to get the vendor's price
for that #apple, I use a method such as the following:

Vendor>>priceOf: aSymbol

Now, to make the setter method, I have followed this pattern:

Vendor>>priceOf: aSymbol is: newPrice

I've seen the suggestions in other responses to this and I don't like them.

Calling "everything" a setter/getter seems to be J-zeitgeist but, what you have here is a collection of prices, indexed by a symbolic key, rooted at instances of Vendor.

Translated to Smalltalk language this is a variant of #at:put:

Vendor>>priceAt: aSymbol put: newPrice

Even more Smalltalk-ish, you'd have

 aVendor pricebook at: aSymbol put: newPrice

People with an education in Smalltalk will immediately understand what's happening when seeing a piece of your code which sends #priceAt:put:, even in the absence of class comments :)

/Klaus

Does this follow traditional patterns?  I'll admit I have read the first
half of "Smalltalk with Style" but not the second.  Should I instead make
the setter method look like this:

Vendor>>setPriceOf: aSymbol to: newPrice

?

Thanks,
Tim

[PS - Thanks to everyone who has been helping me on here lately, I have
been lax in responding.  You all bring up some good ideas and tips.]


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
linux.arklinux....    user-groups.lin...    kde.usability/2...    ietf.ipp/2002-0...    mail.spam.spamc...    os.netbsd.devel...    audio.cd-record...    text.unicode.de...    php.documentati...    games.fps.halfl...    window-managers...    suse.oracle.gen...    bug-tracking.gn...    video.dvdrip.us...    xfree86.cvs/200...    java.netbeans.m...    network.argus/2...    culture.sf.kill...    debian.ports.al...    freebsd.questio...    qplus.devel/200...    handhelds.palm....   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe