OOP Terminology
July 06, 2008
Let me start off by saying that I'm not an OO expert. I started out with ColdFusion 4.5 when it didn't even have functions, so naturally I learnt procedural programming and struggle with the concepts of OOP (Object Orientated Programming). Ben Nadel has recently started blogging about his OOPhoto project, as he attempts to learn OOP. I thought I'd start blogging about the terminology and concepts behind OOP as I learn it. So here goes!
Inheritance
Inheritance is when one object extends another. This allows you to start with a fairly general object which you can then extend with one of more objects to create something very specific.
For example:
Person object methods
- getForename() - returns the first name
- getSurname() - returns the last name
- getGender() - returns the gender
- getDOB() - returns the date of birth
Employee object methods (extends person)
- getJobTitle() - returns the person's job title
- getSalary() - returns the person's job title
Secretary object (extends employee)
- getWordsPerMinute() - returns the number of words per minute the secretary can type
Chef object (also extends employee)
- getMichelinStars() - returns the number of Michelin stars the Chef has been awarded
In the above example we start off with the person object which has properties which apply to all people (gender and date of birth). This is extended by the employee object. Because the employee object extends the person object it inherits the properties and methods of the person object (gender and date of birth). We can take this further and create two new objects which are much more specific variants of an employee. Because secretary and chef extend employee, they also extend person.
What does this all mean?
Our Chef object has the following methods:
- getForename()
- getSurname()
- getMichelinStars()
- getJobTitle()
- getSalary()
- getGender()
- getDOB()
Our Secretary has the following properties:
- getForename()
- getSurname()
- getWordsPerMinute()
- getJobTitle()
- getSalary()
- getGender()
- getDOB()
Why is the useful?
It means that we can reduce duplication of code as we can create simple objects and then, through inhertiance, make more detailed versions to suit our needs.
Polymorphism
This happens as a direct result of inheritance. What it means is that you can treat the inherited methods and properties in a child object exactly the same as we would if we were interacting with the parent object's method directly. The inherited getGender() method of our secretary object is Polymorphic as it behaves exactly the same as the getGender() method of out chef object.
If you're a bit confused by what I mean by parent and child, then the child inherits (by extending) from the parent object.
Encapsulation
Encapsulation basically means hiding the internal workings. Other objects don't need to know how the employee object calculates the salary. Salary may just be a fixed value or it may use a complex formula, either way, other objects don't need to know how, just what the value is. One of the golden rules of encapsulation is that an object's data should not be exposed directly.
Why is this useful?
Because the internal workings are hidden and not important to other objects, we are free to change it without breaking anything else. How many times have we written some code and then had to change it later. Encapsulation to the rescue!
- Posted in:
- ColdFusion
- OOP
11 comments
Leave a comment
If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Good stuff. And thanks for taking notice of OOPhoto. I am gonna start working on the domain model and all feedback would be great!
Comment by Ben Nadel – July 07, 2008
:)
Comment by John Whish – July 08, 2008
You are definitely *not* the only person who has trouble with this. And even more trouble is not so much understanding the terminology (although that is trouble), is bringing it all together in a logical way.
I get very mucked down when people start talking about Service objects and service layers and gateways and that sort of thing. I still don't feel like I have a great handle on what all those do and I see that many people seem to refer to things very differently.
Comment by Ben Nadel – July 08, 2008
Comment by John Whish – July 09, 2008
It's great to see that you are posting about your OOP experiences with Coldfusion because it is something that I am attempting to get to grips with too.
I have also been reading a set of posts on Adrian Moreno's blog which I found useful.
www.iknowkungfoo.com/blog/index.cfm/2007/8/22/Object-Oriented-Coldfusion--1--Intro-to-Objectcfc
/>
Simon
Comment by Simon Bingham – July 15, 2008
I've seen the posts on Adrian Moreno's blog which are a good into to DAOs and Gateways. From my limited knowledge of OOP, it looks like the posts just talk about the "Persistence Layer" (accessing data which is in a stored format i.e. database/XML file) which is only one part of true OO design.
Have a look at Ben Nadel's diagram at:
www.bennadel.com/blog/1286-OOPhoto-Revisualizing-The-Application-Layers.htm
and then imagine another layer beneath the domain model(s). (Feel free to comment Ben *grin*)
I'd also recommend reading a great article by Hal Helms about this:
www.halhelms.com/index.cfm?fuseaction=newsletters.show&issue=122904_badOO
/>
I asked Hal Helms about good books and he recommended "Object-oriented Technology: A Manager's Guide" by David Taylor, which I've just bought but it hasn't arrived yet. Watch this space for my brain exploding!
Comment by John Whish – July 15, 2008
I'm still working on the Service layer. I've hit some big obstacles there. Not even ready to journey down father into the domain yet :(
Comment by Ben Nadel – July 15, 2008
Just wanted to check that I wasn't misinterpreting your diagram. I totally understand your frustration - going OOP just seems like learning to develop all over again!
Comment by John Whish – July 15, 2008
Comment by Ben Nadel – July 15, 2008
Comment by John Whish – July 15, 2008
Comment by Ben Nadel – July 15, 2008