down day

9 Jan

Didn’t get to the Selenium course today, but have been looking at the Big Java book tonight now that everyone’s packed away in their beds. Spent the afternoon caring for a sick wife and child, and feeling a bit under the weather myself. Feeling much better now, myself at least!

I was eager to do this because the next chapter, chapter 9, deals with Interfaces and Polymorphism.

Talk about Fear!

As luck (and a bit of persistence) would have it, I’m well on my way to a basic understanding of interfaces and how to implement them, at a very basic level. The ideas are only just beginning to gel a bit, though, and while I’ve had some very good luck re-tooling some of the older Big Java exercises to utilize an interface (with more than a few peeks at the sample code) I still have trouble describing exactly what it is I see them doing.

At one point there was a bit of an ‘ah ha’ moment where I felt that Objects were nouns, methods were verbs and interfaces were adjectives.

In retrospect, I’m not so sure that analogy has the ring of genius it seemed to at the time!

I do get this, though. An interface doesn’t ‘do’ anything like a typical class. It instead simply contains a list of one or more methods which classes which implement the interface must also contain.

The example interface in the book was called ‘Measurable’, and contained a single method name ‘getMeasure()’ which was implemented in two other classes (a ‘Coin’ class and a ‘BankAccount’ class) each of which had its own getMeasure() method to return a (measurable) value.

That name, ‘Measurable’ is where I got the adjective reference I now recall.

So I could likewise create an interface ‘Noisy’, which could be implemented by classes such as ‘Dogs’, ‘GuitarAmps’ and ‘FratBoys’. The interface could contain methods like ‘howl’, ‘bark’ or ‘wail’, each of which would have to exist in each of the classes. Thanks to the interface, we could then create other classes such as ‘Kennel’, ‘DeltaHouse’ or ‘Nightclub’ (all of which are havens for noisy things) which could then operate on any of the three previous classes without separate code having to be written for each (so long as the common vocabulary specified by the interface was adhered to).

Um…er…something like that!

As for the polymorphism, hey, don’t rush me. I’ll get there. ; )

Advertisements

Comments are welcome!

Fill in your details below or click an icon to log in:

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: