
Chimney allows access to house object
Chimneys Allow Access
The other day I was working on some getters and setters to capture and encapsulate data passed from an input source. I’m most cognizant of using getters and setters for incoming data so that I have these nice encapsulated chunks of coded properties. The reason behind encapsulation is to keep properties from getting changed by other elements in a program unwittingly. So getters and setters became a recommended way of going about setting up data. (The terms mutators (setters) and accessors (getters) are often used to describe the same thing, but I can’t think of mutators without images of zombies, so I just use getters and setters like everyone else—conformist that I am.)
To be honest, most of the programs that I write using design patterns don’t have getters and setters per se, and I rarely use the ActionScript 3.0 get and set methods. Typically, a well-designed program has no need for explicit getters and setters. Nevertheless, on page 20 of our book, Chandima and I dutifully write about getters and setters as being a mundane aspect of OOP and provide several examples. However, over the years, I’ve seen a growing number of articles about the dark side of getters and setters. The issue is around what getters and setters were meant to do and how they have been misused.
If you think of a house as an object, and the doors as public access, both the opportunities and problems with object access become more apparent. Also, you have places where entry is possible but not intended—such as down the chimney. Anyway, I was moved to pen a season-appropriate missive to shed some light on the issue:
The Night Before OOP-SLA
‘Twas the night before OOPSLA, when all through the watt
Not a coder was stirring, not even a bot;
The downloads were placed on the server with care,
In hopes that St. Singleton soon would be there;
The young geeks were nestled all snug by their screens,
While visions of killer apps arose from their dreams;
And mamma with her iMac, and I with my Dell,
Had just settled down to write code for a spell,
When out on the net there arose such a clatter,
I sprang from my chair to see what was the matter.
Away to the keyboard I cranked up my Flash,
Tore open the folders and emptied the trash.
The apps on the iPod all came alive
Gave the lustre of update to objects on-drive,
When, what on my screen came clear in my glasses,
But a miniature program, and eight tiny classes,
With a little old hacker, so fat like a pork,
I knew in a moment it must be St. Dork.
More rapid than skip lists his coursers they came,
And he whistled, and shouted, and called them by name;
“Now, Factory! now, Context! now, Product and State!
On, Flyweight! on Proxy! on, Builder, Template!
To the top of the dock! to the top of the sprawl!
Now refractor! refractor! refractor all!”
As bits wrapped in packets over the routers do fly
When they meet with an obstacle they return to retry,
So up to the server the coursers they flew,
With program dependencies, errors, and St. Singleton too.
And then, in a twinkling, I picked up my mug
Full of java to seek out each little bug.
As I drew in my mouse, and was clicking around,
Down the accessor St. Singleton came with a bound.
He was messing with properties and methods to boot,
My encapsued objects were wrecked to the root;
A bundle of types he had flung on his back,
And he looked like a newbie overloading the stack.
His eyes — how they glazed! his pimples how icky!
His cheeks were like pizzas, his nose was still sticky!
His droll little mouth had precious few graces,
And when he smiled I was blinded by braces;
The stump of a pencil shown up from his pocket protector,
He stumbled around like Clouseau the inspector;
He had a broad face and was fat as a pie,
When he walked he looked like the Comic Book Guy.
He was chubby and plump, a right jolly old geek,
And I laughed when he tried to give my pattern a tweak;
A wink of his eye and a blast of hot gas,
Soon gave me to know that this guy was crass
He spoke not a word, but started hacking his work,
And filled all the memory; then turned like a jerk,
And laying his finger straight up his nose,
And giving a burp, up the access he rose;
He sprang to his program, to his team issued a command,
And the whole thing crashed like a wave on the sand,
But I heard him exclaim, ere he limped out of sight,
“Happy Coding to all and to all a good night.”
Happy Holidays from Bill and Chandima…
Recent Comments