Archive - Originally posted on "The Horse's Mouth" - 2005-02-25 04:34:54 - Graham Ellis
For the second time this year (and it's only the second month), I find that I have a keen bell-ringer on my programming course ... he's off each evening to meet up with fellow bell-ringers in church towers in Wiltshire, and having a really good time outside course hours as well as during the day. I understand that there are a substantial number of excellent sets of bells (I know that the word "set" is wrong) in this area, and I listen in some awe to the complexity described in ringing sequences - how do you get from a string like x16x36x36 to a set of results like:
1 2 3 4 5 6
2 1 4 3 6 5
2 4 1 6 3 5
4 2 6 1 5 3
2 4 6 5 1 3
4 2 5 6 3 1
2 4 5 3 6 1
With so many questions like this one - "how do I get from 'A' to 'B'" - you only need one expert to tell you how to do it, write down and test the algorithm, and then anyone who can provide inputs and read outputs can use the algorithm. In Object Oriented terms, this "hiding information within" approach is known by the term "encapsulation".
Helped by 'George' and 'Sandra', I've learn a little about ringing in the last weeks and yesterday George and I put together a sample program to ring some parts of bell changes, using Perl. Not exactly what he'll be using Perl for at work, but a parallel through which he can practise and learn further. Here's some of the code:
We've set up three methods of ringing, by name and by the number of bells involved in the changes. We've then called a method called "setplace" to define how the changes happen in place notation. Let's then ring the changes:
foreach $curr_method(@method) {
Printing out a header for each set of changes, and getting back an "action list" of what we need to apply:
Yes, that's all there is in my main application! The code that took us a while to work out which interprets the place notation strings and applies it to the rings of bells is all hidden within the file bells.pm which we called in at the top. The typical user doesn't need to know how it works. All they want to do is to run a program like the one above and read:
I HAVE placed the bells.pm on our website if you would like a look - there's a link to it from our Object Oriented Design - Individual Object module as this complex field has proven to be such a great example of the use of encapsulation, even on a quite small project.