What if my constructors are not named init()

16 views
Skip to first unread message

Miguel Ulloa

unread,
Sep 2, 2013, 5:15:31 AM9/2/13
to coldspri...@googlegroups.com
Hello,

Say my constructors were named after the components could I still use ColdSpring?

thanks,
-migueL

Brian Kotek

unread,
Sep 2, 2013, 1:23:31 PM9/2/13
to coldspri...@googlegroups.com
This should only matter if you're using constructor injection, which most people don't. Unless you need dependencies passed as constructor args, I think you should be fine. But obviously you'd want to test to confirm.

If you DO need constructor injection, then you may have problems. Mark can confirm, but as far as I know, CS follows the established convention of the constructors being named init(). This has been the established convention since CFC were introduced in CF 6, and is the default implicit constructor. CF 10 introduced the initMethod metadata option but I've never actually heard of anyone using this. If Mark has incorporated the detection of the initMethod value in CS then this should work. But if not (and as far as I know, it hasn't) then I believe the method would have to be named init() for CS to invoke it as the constructor.

 



--
You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldspring-use...@googlegroups.com.
To post to this group, send email to coldspri...@googlegroups.com.
Visit this group at http://groups.google.com/group/coldspring-users.
For more options, visit https://groups.google.com/groups/opt_out.

Nolan Erck

unread,
Sep 2, 2013, 2:00:40 PM9/2/13
to coldspri...@googlegroups.com
What Brian said.

However...

Granted I haven't looked at the code yet, but my first thought is this would be an easy feature to add to ColdSpring.  In the ColdSpring config file, there could be an option letting you define how your constructors are handled, yes? Meaning, I could specify if I want to use "init", or "new", or the name of the CFC itself (or some other UDF name if I so chose).  Yes? Thoughts?  Am I way off base here?

-Nolan






Dan Wilson

unread,
Sep 2, 2013, 2:04:39 PM9/2/13
to coldspri...@googlegroups.com

It would be more straightforward to add an init() method to the components that in turn called the custom unit methods.

That would be preferred to changing the ColdSpring framework.

Nolan Erck

unread,
Sep 2, 2013, 2:08:28 PM9/2/13
to coldspri...@googlegroups.com
Fair enough.  Though I guess that would depend on how much code was already written, yes? If I have, say, hundreds of CFCs that all use the convention Miguel mentioned, then it'd be easier to edit a config file in ColdSpring (assuming the feature was written into the framework...though I realize this isn't really a high priority item to add). 

-n

Brian Kotek

unread,
Sep 2, 2013, 2:24:07 PM9/2/13
to coldspri...@googlegroups.com
While I'd feel for him if that were the situation, in all my years of using CFCs (since CFMX 6) this is the first time I've ever heard of anyone deliberately disregarding the use of init() as the implicit constructor method. So while the answer is technically "yes, this could be added to the framework", I'd have to assume this would be an extremely low-priority feature request. We're basically talking about asking Marc to change the framework so that one person can avoid having to change their CFCs. To me, that's a lot to ask of Marc, since it's essentially saying Marc should spend the time changing CS instead of Miguel spending time adding one method to his CFCs.

Of course, I have no real idea how easy or difficult this would be to change in ColdSpring. And I'm sure if someone wanted to issue a pull request to add this (with the appropriate tests added), I'm sure Marc would gladly accept it!

And again, unless Miguel needs constructor injection, this is probably not even an issue in the first place. :-)

Mark Mandel

unread,
Sep 2, 2013, 8:27:21 PM9/2/13
to coldspri...@googlegroups.com
For CS1.x I think that if it can't find a init it skips it. But for CS2, I believe it always goes looking for an init.  I'd have to double check.

Mark

Miguel Ulloa

unread,
Sep 4, 2013, 11:59:16 PM9/4/13
to coldspri...@googlegroups.com
Hello guys,

Thanks for your thoughts/responses. I actually do not have any code yet. All the apps I am now supporting follow the CF bean convention and do work great with ColdSpring. However, I have been working with beans for about 9 months now but I still do not fully understand them. I am at least unable to clearly explain it to any one. The best I can do is to describe how to use them. This bothered me so I did some research and I came across WEB4J. This framework is not an IoC but an MVC one and it was build around using immutable objects instead of beans as much as possible. Now my line of thinking did not take me that far however I do agree with their rationale and I immediately understand immutable objects more than I now understand beans. This is what prompted my question. Brian, yes I am looking to fully instantiate at construction.

Miguel Ulloa

unread,
Sep 5, 2013, 12:01:35 AM9/5/13
to coldspri...@googlegroups.com
BTW, I use ColdSpring 2

Brian Kotek

unread,
Sep 5, 2013, 12:29:11 AM9/5/13
to coldspri...@googlegroups.com
If you really want to go down this road, all I'd say is just make init() be your constructor method. It's the default constructor method in CF anyway. You won't gain anything by using a different method as the constructor, and in fact will probably just make your life more difficult.

Personally, I don't think you'd gain much by trying to shoehorn immutable objects into CF. ColdSpring generally manages singleton objects, which usually have no state anyway. You don't typically see many value objects that have no identity in a CF application. Most apps consist of singleton controllers, services, gateways, etc., and entities. None of which seem like good candidates for being immutable. 


On Thu, Sep 5, 2013 at 12:01 AM, Miguel Ulloa <miguel...@gmail.com> wrote:
BTW, I use ColdSpring 2
Reply all
Reply to author
Forward
0 new messages