Static class example

Example of a static Person class which does not store data. In effect it is procedural code wrapped in a cfcomponent tag.


View The Results...

index.cfm
<cfset name = "Jane Smith" />
<cfset Person = CreateObject( "component", "Person" ) />

<cfoutput>
<p>
#Person.sayHello()#<br />
#Person.sayName( name )#<br /> </p> </cfoutput>
Person.cfc
<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>

View The Code...

Hello World!
My name is Jane Smith


« Part 1 Menu