The Artima Developer Community
Sponsored Link

Agile Buzz Forum
How and why to override a method

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
How and why to override a method Posted: Oct 20, 2005 9:52 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: How and why to override a method
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement

One of the things I bring up here is why overriding base library behavior is often useful - I thought it might be a good idea to give an example of that, and show how you manage it in VisualWorks.

Here's a a view of the Browser, with a method overridden:

Browser Showing Override

I've shrunken the image for space reasons, but in the top right you'll see that the method is red. That indicates that I've overriden a method owned by a different package (WithStyle, in this case) in the posting tool's package. The override is this snippet of code I added:


	(value isNil or: [value isEmpty])
		ifTrue: [value := ParagraphEditor currentSelection].

In the method above, "value" holds a string that will be the default choice in a dialog box that is popped up for data entry. In this case, it's popped up when the user wants to insert an image into the post. I figured it would be nice if the tool remembered the last image that got uploaded, and made that the default choice. As it happened, the WS method was usually leaving that choice blank (thus, requiring me to type it all in).

I spoke to Michael, and he told me that better pluggability there would be a good thing. In the meantime though, I'm stuck - unless I override. So I did that, and you see the way the browser displays it - in a way that is easy to pick out. I can also version this override off separate from the WS code (thus, not perturbing their codebase). Later, after they've addressed this, I simply remove the override (a menu pick in the browser) and adjust my code to deal with their pluggability.

Simple, and it gets the job done - and in the interim - unlike the situation with Java, or C# - I don't have to either wait for the vendor, or write an entire replacement library/wrapper to get around the limitation. Two lines added to an override, and I'm done.

Of course, some people "don't trust developers", so they are happy wearing the chains the vendors hand them...

Read: How and why to override a method

Topic: Optimistic vs Pessimistic Messaging Previous Topic   Next Topic Topic: Monday

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use