Define an interface, IAnimal.cfc.
- ColdFusion User Guide
- Introduction to ColdFusion
- About Adobe ColdFusion
- Download Adobe ColdFusion
- What's new in ColdFusion (2023 release)
- ColdFusion (2023 release) Release Notes
- Deprecated Features
- REST enhancements in ColdFusion
- Central Configuration Server
- Server Auto-Lockdown
- Asynchronous programming
- Docker images for ColdFusion
- SAML in ColdFusion
- JSON Web Tokens in ColdFusion
- Use SAML and LDAP in Admin
- Cloud Services in ColdFusion
- ColdFusion and GCP Storage
- ColdFusion and GCP Firestore
- ColdFusion and GCP PubSub
- ColdFusion and Amazon S3
- ColdFusion and DynamoDB
- ColdFusion and Amazon SQS
- ColdFusion and Amazon SNS
- ColdFusion and MongoDB
- ColdFusion and Azure Blob
- ColdFusion and Azure Service Bus
- Multi-cloud storage services
- Multi-cloud RDS databases
- ColdFusion and Azure Cosmos DB
- Install ColdFusion
- Install the server configuration
- Install ColdFusion- Zip Installer
- Install ColdFusion- GUI Installer
- CFSetup configuration tool
- ColdFusion Licensing and Activation
- ColdFusion server profiles
- Prepare to install ColdFusion
- Install the JEE configuration
- Install ColdFusion Express
- Install integrated technologies
- Configure your system
- Troubleshoot installation issues
- Install ColdFusion silently
- Install Adobe ColdFusion (2016 release) hotfix
- ColdFusion (2018 release) - Install JEE configuration
- Use ColdFusion
- Performance Monitoring Toolset
- Overview of ColdFusion Performance Monitoring Toolset
- Auto-discovery of ColdFusion nodes and clusters
- Code profiler in ColdFusion Performance Monitoring Toolset
- Configure ColdFusion Performance Monitoring Toolset settings
- Install ColdFusion Performance Monitoring Toolset
- View cloud metrics
- Monitor GraphQL in Performance Monitoring Toolset
- Configure TLS/SSL and Authentication for Elasticsearch 8.x in Performance Monitoring Toolset
- View cluster and node metrics
- View data source metrics
- View external services
- View incoming services
- View list of sites and busy connections
- View topology of sites
- Datastore Health Monitoring
- Performance Monitoring Toolset Update 1
- Secure Performance Monitoring Toolset with HTTPS/SSL
- Performance Monitoring Toolset deployment guide
- Adobe ColdFusion Builder extension for Visual Studio Code
- Getting started with Adobe ColdFusion Builder extension for Visual Studio Code
- Add a ColdFusion server
- Project Manager
- Work with ColdFusion code
- Profile preferences
- Debug applications
- Refactoring
- Services Browser
- RDS support
- PMT Code Profiler integration
- Security Analyzer report integration
- Known issues in this release
- Getting started with Adobe ColdFusion Builder extension for Visual Studio Code
- Use ColdFusion Builder
- About ColdFusion Builder
- System requirements | ColdFusion Builder
- Install ColdFusion Builder
- Edit code in ColdFusion Builder
- Manage servers in ColdFusion Builder
- Manage projects in ColdFusion Builder
- What's new in Adobe ColdFusion Builder (2018 release)
- Frequently Asked Questions (FAQ) | Adobe ColdFusion Builder (2018 release)
- Debug applications in ColdFusion Builder
- ColdFusion Builder workbench
- ColdFusion Builder extensions
- Debugging Perspective in ColdFusion Builder
- Build mobile applications using ColdFusion Builder
- Bundled ColdFusion Server
- Debug mobile applications in ColdFusion Builder
- Use extensions in ColdFusion Builder
- Coldfusion API Manager
- Overview of Adobe ColdFusion API Manager
- Features in ColdFusion API Manager
- Get started with ColdFusion API Manager
- Install ColdFusion API Manager
- Authentication types
- Create and publish APIs
- Administrator
- Subscriber
- Throttling and rate limiting
- Notifications
- Connectors
- Set up cluster support
- Integrate ColdFusion and API Manager
- Metrics and Logging in API Manager
- Generate Swagger documents
- Configure SSL
- Known issues in this release
- Policies in ColdFusion API Manager
- Create a Redis cluster
- Multitenancy in API Manager
- Docker images for ColdFusion API Manager
- Configure and administer ColdFusion
- Administer ColdFusion
- Use the ColdFusion administrator
- Data Source Management for ColdFusion
- Connect to web servers
- Deploy ColdFusion applications
- Administer ColdFusion security
- Basic Troubleshooting and FAQs
- Work with Server Manager
- Use multiple server instances
- WebSocket Enhancements (ColdFusion 11)
- Security Enhancements (ColdFusion 11)
- Work with Server Monitor
- ColdFusion Administrator API Reference
- CFML Reference
- Introduction to CFML Reference
- Reserved words and variables
- ColdFusion tags
- ColdFusion functions
- Ajax JavaScript functions
- Ajax JavaScript functions
- Function summary Ajax
- ColdFusion.Ajax.submitForm
- ColdFusion.Autosuggest.getAutosuggestObject
- ColdFusion.Layout.enableSourceBind
- ColdFusion.MessageBox.getMessageBoxObject
- ColdFusion.ProgressBar.getProgressBarObject
- ColdFusion.MessageBox.isMessageBoxDefined
- JavaScriptFunctionsinColdFusion9Update1
- ColdFusion ActionScript functions
- ColdFusion mobile functions
- Application.cfc reference
- Script functions implemented as CFCs
- ColdFusion Flash Form style reference
- Styles valid for all controls
- Styles for cfform
- Styles for cfformgroup with horizontal or vertical type attributes
- Styles for box-style cfformgroup elements
- Styles for cfformgroup with accordion type attribute
- Styles for cfformgroup with tabnavigator type attribute
- Styles for cfformitem with hrule or vrule type attributes
- Styles for cfinput with radio, checkbox, button, image, or submit type attributes
- Styles for cftextarea tag and cfinput with text, password, or hidden type attributes
- Styles for cfselect with size attribute value of 1
- Styles for cfselect with size attribute value greater than 1
- Styles for cfcalendar tag and cfinput with dateField type attribute
- Styles for the cfgrid tag
- Styles for the cftree tag
- ColdFusion Flash Form Style Reference
- ColdFusion event gateway reference
- ColdFusion Event Gateway reference
- addEvent
- CFEvent
- CFEventclass
- Constructor
- Gateway development interfaces and classes
- getStatus
- setCFCPath
- setCFCMethod
- getOriginatorID
- getLogger
- getBuddyList
- getBuddyInfo
- IM gateway message sending commands
- IM Gateway GatewayHelper class methods
- onIncomingMessage
- onIMServerMessage
- onBuddyStatus
- onAddBuddyResponse
- onAddBuddyRequest
- IM Gateway CFC incoming message methods
- IM gateway methods and commands
- CFML CFEvent structure
- warn
- info
- setOriginatorID
- data command
- submit Multi command
- submit command
- setGatewayType
- setGatewayID
- setData
- setCFCListeners
- outgoingMessage
- getStatusTimeStamp
- numberOfMessagesReceived
- numberOfMessagesSent
- removeBuddy
- removeDeny
- removePermit
- setNickName
- setPermitMode
- setStatus
- SMS Gateway CFEvent structure and commands
- SMS Gateway incoming message CFEvent structure
- getStatusAsString
- getProtocolName
- getPermitMode
- getPermitList
- getNickName
- getName
- getDenyList
- getCustomAwayMessage
- getQueueSize
- getMaxQueueSize
- getHelper
- getGatewayType
- getGatewayServices
- getGatewayID_1
- getGatewayID
- getData
- getCFCTimeout
- setCFCTimeout
- getCFCPath
- getCFCMethod
- GatewayServices class
- Gateway interface
- GatewayHelper interface
- addPermit
- addDeny
- addBuddy
- error
- debug
- Logger class
- stop
- start
- CFML event gateway SendGatewayMessage data parameter
- restart
- fatal
- SMS gateway message sending commands
- ColdFusion C++ CFX Reference
- ColdFusion Java CFX reference
- WDDX JavaScript Objects
- Develop ColdFusion applications
- Introducing ColdFusion
- Changes in ColdFusion
- Changes in ColdFusion
- Replacement of JRun with Tomcat
- Security enhancements
- ColdFusion WebSocket
- Enhanced Java integration
- ColdFusion ORM search for indexing and search
- Solr enhancements
- Scheduler enhancements
- Integration with Microsoft Exchange Server 2010
- RESTful Web Services in ColdFusion
- Lazy loading across client and server in ColdFusion
- Web service enhancements
- Displaying geolocation
- Client-side charting
- Caching enhancements
- Server update using ColdFusion Administrator
- Secure Profile for ColdFusion Administrator
- Introduction to application development
- The CFML programming language
- Building blocks of ColdFusion applications
- Develop CFML applications
- Develop CFML applications
- Design and optimize a ColdFusion application
- Handle errors
- Use persistent data and locking
- Use ColdFusion threads
- Secure applications
- Client-side CFML (for mobile development)
- Use the ColdFusion debugger
- Debugging and Troubleshooting Applications
- Develop globalized applications
- REST enhancements in ColdFusion
- Authentication through OAuth
- Social enhancements
- Develop mobile applications
- Access and use data
- ColdFusion ORM
- ColdFusion and HTML5
- Flex and AIR integration in ColdFusion
- Request and present information
- Office file interoperability
- ColdFusion portlets
- Work with documents, charts, and reports
- Use web elements and external objects
- Use external resources
- Send and receive e-mail
- Interact with Microsoft Exchange servers
- Interact with remote servers
- Manage files on the server
- Use event gateways
- Create custom event gateways
- Use the ColdFusion extensions for Eclipse
- Use the data services messaging event gateway
- Use the data management event gateway
- Use the FMS event gateway
- Use the instant messaging event gateways
- Use the SMS event gateway
To learn about ColdFusion components, see Build and use ColdFusion components.
Read on to know the new and enhanced OOP features in ColdFusion.
Abstract components and methods
An abstract component can have abstract method without body and can also have methods with implementation.
Use the abstract keyword to create an abstract component and method. In ColdFusion, you cannot instantiate an abstract component. An abstract component is mostly used to provide base for sub-components. The first concrete component should have the implementation of all the abstract methods in its inheritance hierarchy.
A concrete component cannot have abstract methods.
To declare an abstract component,
// myAbstractClass.cfc abstract component { // abstract methods // concrete methods }
That is all there is to when declaring an abstract component in ColdFusion.
You cannot create instances of myAbstractClass. Thus, the following code is NOT valid:
myClassInstance=new myAbstractComponent();
Here is an example of using abstract components in ColdFusion.
Shape.cfc
abstract component Shape{ abstract function draw(); }
Square.cfc
component Square extends="Shape" { function draw() { writeoutput("Inside Square::draw() method. <br/>"); } }
ShapeFactory.cfc
component ShapeFactory extends="AbstractFactory" { Shape function getShape(String shapeType){ if(shapeType EQ "RECTANGLE"){ return new Rectangle(); }else if(shapeType EQ "SQUARE"){ return new Square(); }else return "not defined"; } }
Rectangle.cfc
component Rectangle extends="Shape" { function draw() { writeoutput("Inside Rectangle::draw() method. <br/>"); } }
AbstractFactory.cfc
abstract component AbstractFactory { abstract Shape function getShape(String shape) ; }
FactoryProducer.cfc
component FactoryProducer { AbstractFactory function getFactory(String choice){ if(choice eq "SHAPE"){ return new ShapeFactory(); } } }
index.cfm
<cfscript> //get shape factory shapeFactory = new FactoryProducer().getFactory("SHAPE"); //get an object of Shape Rectangle shape2 = new shapeFactory().getShape("RECTANGLE"); //call draw method of Shape Rectangle shape2.draw(); //get an object of Shape Square shape3 = new shapeFactory().getShape("SQUARE"); //call draw method of Shape Square shape3.draw(); </cfscript>
Final component, method, and variable
In ColdFusion, inheritance is a highly useful feature. But at times, a component must not be extended by other classes to prevent data security breaches. For such situations, we have the final keyword.
ColdFusion supports the following:
- Final component
- Final method
- Final variable
Final variable
Final variable are constants. Use the final keyword when declaring a variable. You cannot change the value of a final variable once you initialize it. For example,
component{ final max=100; function mymethod(){ //max=100; writeoutput("final variable is: " & max); } }
Create an index.cfm, instantiate the component, and call the method defined in the component. If you change the value of max in the method, you see an exception. The following snippet also produces an exception.
component{ final max; // constructor function mymethod(){ max=50; writeoutput("final variable is: " & max); } }
Final component
You cannot extend a final component and override a final method. A final component, however, can extend other components.
To define a final component, see the example below:
final component{ // define methods }
To define a final method, use the specifier before the final keyword and the return type. For example,
public final void function myMethod() { // method body }
A final component helps secure your data. Hackers often create sub-components of a component and replace their components with the original component. The sub-component looks like the component and may perform a potentially malicious operation, which would compromise the entire application. To prevent such subversion, declare your component as final and prevent the creation of any sub-component. For example,
A.cfc
final component { }
The code below produces an exception:
B.cfc
component extends=”A” { }
Final method
A method with a final keyword cannot be overridden. This allows you to create functionality that cannot be changed by sub-components. For examples,
Test.cfc
component { // final method and cannot be overridden public final void function display(){ writeOutput("From super class, final display() method"); } // concrete method public void function show(){ writeOutput("From super class, non-final show() method"); } }
Demo.cfc
component extends="Test"{ //public void function display(){} public void function show() { writeOutput("From subclass show() method"); } }
In Demo. cfc , uncommenting the above line produces an exception, since you cannot override a Final method. You can, however, override a non-final method, as shown in the code above.
main.cfm
<cfscript> d1=new Demo(); d1.display(); d1.show(); </cfscript>
Output
From super class , final display() method
From subclass show() method
Default functions in interfaces
This feature enables you to declare a function in an interface, and not just the signature. While extending the interface, developers can choose to either override or reuse the default implementation.
Default Functions enables extending the interfaces without breaking old applications.
For example, create an interface, I.cfc, that defines a function returnsany, which returns an object of any type. Use the keyword "default", while defining such functions.
interface { public default any function returnsany(any obj) { return obj; } }
Create a cfc, comp.cfc, that implements the interface, I.cfc.
component implements="I" { }
Now, create on object that returns a string.
<cfscript> myobj=new Comp(); writeOutput(myobj.returnsany("hello world")); </cfscript>
Covariance
Covariance is the relationship between types and subtypes. In ColdFusion (2021 release), Covariance is supported for return types in overriding a method.
In ColdFusion (2021 release), a return type is covariant in the component implementing the interface. The example below shows how you can leverage covariance.
The argument name is not compared during interface implementation, i.e, if the interface function takes argument name as x , the implementing function in the component can have any argument name.
-
interface displayName="IAnimal" hint="Animal Interface."{ any function eat(any prey=""); any function makeNoise(string noise); }
-
Define component, Animal.cfc, which implements the Interface.
While implementing the interface function eat() & makenoise (), it overrides the return type to a more specific type. This is known as Covariant Method Return Type.
component implements="IAnimal" displayname="Animal"{ property animalSize; property animalType; function init(animalSize,animalType){ variables.instance.animalSize = arguments.animalSize variables.instance.animalType = arguments.animalType } Animal function eat(any prey=""){ return prey; } string function makeNoise(string noise){ return noise; } function getanimalSize(){ return variables.instance.animalSize } function getanimalType(){ return variables.instance.animalType } }
-
Create index.cfm and check how the animal eats and makes noise.
<cfscript> bunny=new Animal('small','rabbit'); simba =new Animal('large','Tiger'); writeoutput("Simba eats " & simba.eat(bunny).getAnimaltype() & "<br/>"); writeoutput("Simba " & simba.makenoise('roarsss')); </cfscript>
Sign in to your account