A Paradigm shift (Or how to learn OOP on the job with out screwing up).
I have been banging my head against CFOOP for about a year or two and thought I would share some of my tricks, trials and tribulations.
I just noticed how my thinking has changed when developing apps these days.
Huh... Thinking about thinking is meta-cognition. So what do you call thinking about what you are thinking about when thinking about metadata? I smell a cognitive infinite recursive loop in the making. (Note to self.. Tell brain to STFU for a minute so I can finish this blog entry FFS)
Anyways...
1. I write the procedural code to get the things I need done. I don't even think about OO at this point.
2. I turn everything into functions and try to atomize things as much as I can (where it makes sense to at least).
3. Then I create a CFC (or CFCs) to organise my functions
4. Then I rewrite my procedural code to incorporate my cfcs/functions
5. I turn THAT code into another function or set of functions
6. And then I turn THAT set of functions into another CFC (0ne ring to rule them all). IIRC this is your service layer.
I got into this whole head set from reading Head First Object-Oriented Analysis and Design.
Taking on this approach has really helped me a lot. When you are getting into a new discipline /paradigm shift /cognitive restructuring such as OOP it can be *VERY* overwhelming and it is *all too easy* to think yourself utterly stupid to the point where you are a quivering blob of "WTF?" before you even write your first line of code. So much so that you say fark it and go back to writing code like you used to (not good).
I have seen it time and time again both in my personal life and from reading interblargs.
What I find with this iterative, incremental approach is that if you get into time crunch, or think yourself stupid, or get in over your head, or get stuck, you can always bail out and still have a functioning app that you can go back to and clean up at a later date.
This approach has really allowed me to push my limits when I can (Read: on the clock) and bail out when I have/need to. And after a while you just start to think differently about code and writing OO code becomes a natural part of your daily affairs. I find myself looking at legacy code and thinking "What can I abstract into a function" or "How can I clean this heaping pile of spaghetti into something more useable". And the next thing you know you are seeing everything in those terms. Your thinking has changed.
The end result on my last foray into OOP was three tidy function calls to a cfc that turned (what was) 500 lines of copy and paste spaghetti code into:
usercfc.createAccount(somestruct)
usercfc.updateAccount(somestruct)
usercfc.deletedAccount(somestruct)

