CFUnited 2008 – OO Best Practices
I attended Hal Helm’s preso on Object Oriented Best Practices on Day 1 of CFUNITED 2008.
I really enjoy hearing Hal speak about OO. He tends to make the hard stuff easy, and he is an excellent presenter.
Phil Duba posted some notes from the session, and he did a much more thorough job of taking notes than I did.
I was not able to find the slides available online, so I have included some of my notes below.
- Objects are about Behavior (don’t micromanage, forget about the data and the database)
- Objects interact with other objects by sending/receiving messages
- Objects should be minimal, complete
- Objects should be Open (for extension) and Closed (from modification)
- He recommends in his Java class that methods should be no longer than 6 lines. Since CF is more verbose, maybe 15 lines max.
Hal gave an example of an Employee scenario where you might be inclined to have an employee that can be either hourly or salaried. I would do a terrible job of trying to explain this, so I found a post by Brian Kotek that goes over this in detail from a talk Hal gave at CF.Objective().
Hal continued:
- prefer composition or aggregation over inheratence. i.e. “is a” vs “has a”
- use design patters
- create custom exceptions
- bundle components behind a facade
- create coding standards
- don’t confuse “Java” with “OO”
- use onMissingMethod for getters/setters
- Ask “Why?”
- Approach development systematically; start with the UI, forget the DB.
- Don’t force everything into objects, not everything belongs there.
He demoed a really cool little app that was able to inspect objects.
I wrote down “persistence generator, object inspector”, but I don’t exactly know what he called this app, nor do I remember if this was something he was planning on releasing.
Basically, he had this app inspecting the Henry VIII family tree.
Anyway, I was a bit overwhelmed by the end of the preso, so that is pretty much all I remember.
Leave a Reply