Showing posts with label Interfaces. Show all posts
Showing posts with label Interfaces. Show all posts

Wednesday 18 February 2015

"ColdFusion Interfaces": a question from a reader

G'day:
One of my readers hit me up with a question about interfaces in CFML:

[...] I would like to ask you a question please. I was unable to find a recent good article by you or anyone else about this topic.

ColdFusion Interfaces; do you rekon using them or not please? Please provide why you would not reckon using ColdFusion Interfaces. [...]

I started looking at this yesterday which explains yesterday's blog post, but I got sick of writing before I had a chance to actually answer. Now I'm sitting at my folks' place (sans rat, today), in the middle of a power outage. Fortunately my battery is charged up, and I can answer this one without any research, so here we go.

Tuesday 17 February 2015

CFML: Interface fulfilment via mixin

G'day:
So a day after I say I'm gonna leave this blog be for a while, I'm back. It's like how I said I was ditching CFML and going to PHP on this blog. Basically I just lie, don't I?

Well I'm sick of writing this bloody book for the day, and I've got a reader question to answer which I decided to follow up on. But first I did some prep work and found something moderately intriguing. Well as intriguing as CFML's interface implementation gets, anyhow.

Friday 12 July 2013

CFML: Trying to be sneaky and failing

G'day:
As I said in my previous article, it's a bit of a slow day in the office today, so I'm just sitting here hitting ColdFusion interfaces with a sledgehammer to see what happens. I was trying to be clever, and have failed miserably. Oh well.

When I was fiddling around trying to work out "WTF" in that previous article, I ended up with this code.

A vanilla interface:

// TestInterface.cfc
interface {

    public numeric function length(required string s);

}

A CFC which implements it:

// Impl.cfc
component implements="TestInterface" {

    public numeric function length(required string s) {
        return len(s);
    }

}

And some code that mungs around with it:

writeOutput("Initial state<br>");
impl = new Impl();
writeOutput('isInstanceOf(impl, "TestInterface"): ' & isInstanceOf(impl, "TestInterface") & "<br>");
writeOutput("<hr>");


writeOutput("After clearance<br>");
impl = new Impl();
structClear(impl);
writeOutput('isInstanceOf(impl, "TestInterface"): ' & isInstanceOf(impl, "TestInterface") & "<br>");
writeOutput("<hr>");


writeOutput("Restored to working order<br>");
impl = new Impl();

public numeric function length(required string s) {
    return len(s);
}
impl.length = length;

writeOutput('isInstanceOf(impl, "TestInterface"): ' & isInstanceOf(impl, "TestInterface") & "<br>");
writeOutput("<hr>");

Stand-alone repro case for that weird interface bug

G'day:
This is a follow-up to the article from yesterday detailing some weirdness I was getting when using Mockbox to mock methods in CFCs which implemented interfaces.

I have no factored-out Mockbox as a factor in this issue. The tangentially-related issues in Mockbox still stand, but I wanted to have a repro case that did not have any third party code in it. And now I have one.

Thursday 11 July 2013

Weird issue with MockBox and interfaces: issue identified

G'day:
A coupla days back I wrote a vague article "Weird issue with Mockbox and interfaces", which detailed some weirdness I was seeing with using Mockbox to mock methods in CFCs which implement an interface.  The short version is that on the first use of a method mocked this way, I was getting this error:

coldfusion.runtime.InterfaceRuntimeExceptions$ArgumentsMistmatchException: Function argument mismatch.[etc]

However if one just re-ran the test, the problem went away. In fact it was only the first usage of the mocked method after ColdFusion was started that caused the problem. Subsequent runs: all good. Restart CF: problem. This is on ColdFusion 9 & 10, but not Railo.

Tuesday 9 July 2013

Weird issue with Mockbox and interfaces

G'day:
This is not gonna be a very well-realised article, as it's posing a question that I've not really been able to flesh out yet.

Saturday 11 May 2013

Interface inheritance what one can and what one cannot do

G'day:
Today's article is brought to you via my baby netbook, as I sit on my bed in my hotel room in Portumna, Co. Galway in the the Republic of Ireland. My ex-wife and my son (25-months-old) live in Portumna, and this is why I pop across to Ireland every two or three weeks (you might have heard me mention it on Twitter or elsewhere). I get to see my boy for four hours on Sat and Sun, every - as I said - 2-3wks. This sux, but that's the way it is.

I only have internet here if I go sit halfway down the stairs, and despite that being doable as I'm the only guest here this weekend, it's a bit cold for that today. So I'm writing this article without the benefit of docs or fact checking! Wish me luck. Or enjoy picking apart whatever it is I end up getting wrong. Heh: in reality I will check everything before I publish... the internet works in the bar downstairs, so I'll proof-read and publish over an early evening Guinness.

Wednesday 8 May 2013

An Architect's View: Sean's feedback on my recent article about ColdFusion interfaces

G'day:
It's a good day for this blog when someone like Sean Corfield reacts to something I write with an article-sized response in the comments. I've asked him if it's OK to reproduce this as a "guest-author" article, which he's agreed to. I did this because I freely admit I'm making up my opinion regarding ColdFusion's interface implementation as I go along, whereas Sean knows an awful lot about the subject - and had a hand in their genesis - as far as CFML goes. So if I'm discussing this topic, his opinions are important ones to reflect upon.

Below is a reproduction of his comment posted against my article entitled "Interfaces in CFML. What are they for?". I have some opinions on this - actually most are "yeah, good point" - but I'll cover them in a separate article.

Thanks, Sean, for taking the time to write this:

A case for interfaces in CFML

G'day:
Yesterday I slapped together a reasonably incoherent article discussing the very basics of how interfaces are implemented in CFML, and tried to give an example of where one might consider using interfaces rather than fall back to class inheritance. Basically my take on interfaces is that they define a behavioural or integration contract, rather than define what it is to be an object (which is what the CFC itself defines).

Tuesday 7 May 2013

Interfaces in CFML. What are they for?

G'day:
Now this will be an interesting one. Not "interesting" as in "fascinating" but "I dunno what I'm gonna write yet, so it'll be interesting to see what I come up with". So possibly more interesting to me during the writing process that to you during the reading process.

I've just been having a conversation on Twitter about interfaces (ie: the <cfinterface> kind), and I recalled that at some stage I was gonna have a look at them in depth to completely get my brain around them. This notion predates this blog, but it's been something I've meant to cover at some stage.