The idea is that when you have some code to write you first do so as if methods existed already to perform the high level operations. Say you want to write some code that tells you how many songs and albums you have by a given artist. Programming languages don't have methods do to this baked in but you pretend they do. An extreme example of the practice would be:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
albums = getAllAlbumsBy(artist); | |
songs = getAllSongs(artist); | |
printSongCountHeader(songs.size()); | |
pringAlbumCountHeader(albums.size()); |
I came up with this example in about thirty seconds so I hope it isn't to opaque.
You may then go on to write the above methods in the same way:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Collection getAllAlbumsBy(Artist artist){ | |
List results = new ArrayList(); | |
for(Iterator i = getAllAlbums();i.hasNext();){ | |
Album album = (Album)i.next(); | |
if(album.isBy(artist)){ | |
results.add(album); | |
} | |
} | |
return results; | |
} |
and so on and so on. Anyway, don't know how many people out there use this style but I've found it really helpful when I need to keep focused on the task/flow at hand without getting to distracted by the details of an issue. Maybe it will help someone else too.