Abstraction means hiding how something works behind a simple, named operation — the caller of user.save() doesn't need to know it involves validating fields, building SQL, and running a query. This lesson covers that general idea, plus a specific CFML feature: components and methods that can be marked abstract, meaning they exist purely to be extended, never used directly on their own.
Learning Objectives
After completing this lesson, you'll be able to:
- Explain abstraction as hiding complexity behind a simple method name.
- Mark a component abstract so it can't be instantiated directly.
- Declare an abstract method that every subclass is required to implement.
Abstraction as Hiding Complexity
This is the same idea that's been used throughout the whole course, just formalized: dateFormat(now(), "...") hides the actual date-formatting logic. serializeJSON(data) hides the details of JSON encoding. A well-designed method does the same thing for your own logic — the caller gets a simple name, not the implementation.
abstract Components (ColdFusion 2018+)
An abstract component is a base class that only makes sense as something to extend — instantiating it directly is a mistake ColdFusion can now catch for you.
abstract component {
abstract public numeric function area();
}component extends="Shape" {
property name="radius" type="numeric";
function init(required numeric radius) {
variables.radius = arguments.radius;
return this;
}
public numeric function area() {
return 3.14159 * variables.radius * variables.radius;
}
}abstract is a CFScript-only keyword — there's no <cfcomponent>/<cffunction> tag-syntax attribute for it, so this one has no Tag Syntax version. Everything that consumes an abstract component (instantiating a concrete subclass, calling its methods) works identically in both syntaxes, as shown next.
What Happens if You Try to Instantiate It Directly
abstract public numeric function area() in Shape.cfc has no body at all — it's just a required signature. Any concrete (non-abstract) subclass must implement it, or ColdFusion raises an error.
Common Beginner Mistakes
Trying to instantiate an abstract component directly
new Shape() fails on purpose — abstract components exist only to be extended. Instantiate a concrete subclass instead.
Forgetting to implement an abstract method in a subclass
A subclass that extends an abstract component must implement every abstract method it declares, or ColdFusion raises an error when that subclass is used.
Best Practices
- Mark a base component abstract whenever it only makes sense as something to extend — it turns a design intention into something ColdFusion actually enforces.
- Keep abstract method signatures minimal — just the name, arguments, and return type needed for subclasses to implement consistently.
Interview Questions
What does marking a component abstract prevent?
It prevents that component from being instantiated directly with new — it can only be extended, and a concrete subclass must be instantiated instead.
What's required of a subclass that extends a component with an abstract method?
It must provide a real implementation of every abstract method declared on the parent, or ColdFusion raises an error.
Summary
In this lesson, you covered abstraction as hiding complexity behind a method name, and ColdFusion's abstract keyword for base components and methods meant only to be extended, never instantiated directly.
What's Next?
The next lesson covers interfaces — a contract of method signatures a component can implement, independent of any inheritance relationship.