Example of a static Person class which does not store data. In effect it is procedural code wrapped in a cfcomponent tag.
<cfset name = "Jane Smith" /> <cfset Person = CreateObject( "component", "Person" ) /> <cfoutput> <p> #Person.sayHello()#<br />
#Person.sayName( name )#<br /> </p> </cfoutput>
<cfcomponent displayname="I am an example of a Static Class" output="false" hint="I am basically just a bunch of functions wrapped in a component"> <!--- =================================================================== Public Methods =================================================================== ---> <cffunction name="sayHello" access="public" output="false" returntype="string" hint="I return a simple string"> <cfreturn "Hello World!" /> </cffunction> <cffunction name="sayName" access="public" output="false" returntype="string" hint="I return a simple string"> <cfargument name="name" required="true" type="string" hint="I am the person's name" /> <cfreturn "My name is " & arguments.name /> </cffunction> </cfcomponent>
Hello World!
My name is Jane Smith