This is a very big topic and you might get a more in-depth response if
you posted your question on the cfcdev list, which focuses on CFCs and
OOP.
A word of caution though if you are approaching OOP for the first time
is that CF isn't an ideal OOP language. Your rewrite might end up
doing more harm than good if you aren't careful, especially if it is a
high-traffic site. The code I write in Java and .NET isn't code that I
would write in ColdFusion. In my experience, ColdFusion suffers
significant performance and RAM hits when you instantiate numerous
objects, even simple ones, unless you instantiate them using Java code
embedded inside of CF. To counteract this performance hit I favor
light-weight pseudo Data Transfer Objects or pseudo Value Objects
which focus on data storage, and move the functions to helper classes.
By "pseudo" I mean structures (StructNew() type structures) that
mirror DTOs or VOs that you can cast to object instances if necessary.
Again, I do this because CF isn't good at handling objects and I find
this technique to work well given that limitation, not because this is
the purest OOP way to do things. There are plenty of healthy
discussions on the best techniques in the cfcdev mailing list
archives. If you prefer a pure OOP design for your site I think you
will find ColdFusion to be limiting as you dig deeper into this topic.
-Mike Chabot
On Tue, Oct 21, 2008 at 6:35 PM, Judah McAuley <[EMAIL PROTECTED]> wrote:
> I'm migrating the backend portion of an application from a procedural
> set of code to a cfc-based and hopefully more OO oriented design. For
> this first go around I won't be using any of the MVC frameworks (the
> front end is already written on this project) and I don't plan on
> using any of the ORM's like Transfer quite yet.
>
> Right now I'm sitting down and listing all the classes I'm going to
> need and sketching out their methods and I've come up against a best
> practices question.
>
> Lets say I have a User object. The user has properties of id, first
> name, last name, company and date of birth lets say.
>
> Some setups I've seen would write a getter/setter (accessor/mutator)
> for each property in that object along with a method to retrieve a
> whole object and a set of objects. (at this point I'm using the words
> object, bean and class interchangeably. I understand that I might be a
> bit off there). So if I wanted to display a user with the id 10, I'd
> say currentuser = User.getUser(10) which would return a struct with
> the User object (bean, whatever). Then if I wanted that user's name,
> I'd say currentuser.getFirstName(). If I wanted to change that users
> first name to Bob, I'd say currentuser.setFirstName('Bob')
>
> Other setups I've seen don't seem to write getters and setters for
> each property but rather create methods that act on the object level.
> So I'd say currentuser = User.getUser(10) and then if I wanted that
> persons first name, I'd just reference it as currentuser.first_name
> and if I wanted to set his name to Bob, I'd say currentuser.first_name
> = 'Bob' and then call User.saveUser(10) and let it persist the change
> that I made to the struct.
>
> Is there a consensus on the best way to approach this? What are the
> most useful tutorials out there for someone setting up their first go
> around with OO while not using a framework?
>
> Thanks,
> Judah
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314205
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4