DevLearningTools

MODULE 7 · LESSON 02

Class vs Object (using CFCs)

How the general OOP terms "class" and "object" map to ColdFusion specifically — a CFC as the blueprint, and each instantiated instance as the object.

New lessons are added one at a time as the course gets built out — a graded quiz for each lesson is still on the way.

"Class" and "object" are general OOP vocabulary, used across every OOP language. ColdFusion doesn't have a class keyword — a CFC plays that role. This lesson is about mapping the general terms onto what's actually in front of you when writing CFML.

Learning Objectives

After completing this lesson, you'll be able to:

  • Explain the relationship between a class/CFC and an object/instance using a concrete analogy.
  • Create a CFC and instantiate more than one independent object from it.
  • Explain why changing one instance's data doesn't affect another instance from the same CFC.

The Blueprint Analogy

A class is a blueprint — it describes what every object built from it will have (properties) and what it will be able to do (methods), but it isn't a real, usable thing by itself. An object is one actual instance built from that blueprint, with its own independent copy of the data.

In ColdFusion, the CFC file is the blueprint. Each time it's instantiated, a separate object is created — each with its own values for the CFC's properties.

One CFC, Many Independent Objects

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

user1 and user2 are two separate objects created from the same CFC (User.cfc) — each has its own independent name, so changing one never affects the other.

Common Beginner Mistakes

Confusing the CFC file with an object

User.cfc on its own is the class/blueprint — nothing is usable until it's instantiated with new User(). The result of that instantiation is the actual object.

Expecting two instances of the same CFC to share data

Each new Component() call produces a fully independent object with its own copy of the properties — changing one instance's data has no effect on another instance made from the same CFC.

Interview Questions

In ColdFusion, what plays the role of a "class" from general OOP terminology?

A ColdFusion Component (a .cfc file) — it's the blueprint that objects get instantiated from.

If you create two instances from the same CFC, do they share the same property values?

No — each instance has its own independent copy of the CFC's properties, set separately during that instance's own construction.

Summary

In this lesson, you covered how the general "class" and "object" terms map onto ColdFusion's CFCs and instances, and confirmed that instances made from the same CFC are fully independent of each other.

What's Next?

The next lesson covers actually creating a CFC file — the component syntax, and the rules a .cfc file has to follow.