Examples and Examplar methods now reconciled!

Hi all

I implemented the <examplar> to behave as suggested by Torsten in thread more than a year ago if I got it correctly and it is available in less than 5 min (I loved it). An examplar is JUST a class method returning an instance. For example :), here I just define a class method returning a grid object.

CTGrid class >> grid22
<examplar>
“self grid22”
| grid1 |
grid1 := self new: 2.
grid1 atRow: 1 atColumn: 1 put: 1.
grid1 atRow: 1 atColumn: 2 put: 3.
grid1 atRow: 2 atColumn: 1 put: 2.
grid1 atRow: 2 atColumn: 2 put: 4.
^ grid1

You can use this method as any class method in the past. NOTHING new!!
So in particular your test can use it to build a fixture (yes reuse). You can use this method in several test cases (yes reuse).

Now nautilus supports nicely <examplar> methods: you can execute them and get a cool GTInspector open on them. So this is similar to the method exampleSomething pattern from Nautilus point of view.

And now people can use exampleSomething to create/open/display… their lovely examples (that may not return instances) – no stress you have the example you always liked (me too). And we get examplar methods that must return an instance but can behave as example from Nautilus perspective. So a nice win/win:

Better documentation of classes, better code reuse, nice integration and dead simple implementation: One class, 3 methods, no more  🙂

If you want to try

https://pharo.fogbugz.com/f/cases/18964/support-examplar

If you want to try you can load the CTGrid packages.

ScriptLoader new unloadPackageNamed: ‘Collections-Grid’.
ScriptLoader new unloadPackageNamed: ‘Collections-Grid-Tests’.
“Because there were not good and will be removed from the image”
Gofer it
url: ‘http://smalltalkhub.com/mc/StephaneDucasse/Containers/main&#8217;;
configurationOf: ‘Grid’;
loadStable

Click on class side of CTGrid and press the triangle and yes you get an inspector on this instance.

Stef

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: