Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion

ColdFusion: Article

What's an Object? An Introduction to OOP

An introduction to object-oriented programming for ColdFusion developers

To put it extremely simply, you already know what an object is. Objects are all around you. If you look at the computer you spend countless hours a day using, that will serve as a good example of what an object is in the real world. One of the amazingly powerful things about software objects is that they're designed to model real-world objects, and do quite a good job of it!

Your computer is an object, and as an object it has certain characteristics such as brand, processor type and speed, amount of RAM, hard drive size, etc. In object lingo, these characteristics are called attributes. Your computer can also do things (sometimes it doesn't do what you want it to do, but it's still doing something!). It can power up, launch applications, automatically run tasks such as a virus scan, and power down. In object parlance these things that your computer can do would be referred to as methods (or sometimes they're referred to slightly less accurately, at least from an OOP standpoint, as functions).

In addition to attributes and methods, perhaps the most important characteristic of an object is that it's self-contained. As I said earlier I'm not going to dive into the differences between procedural programming and OOP at this point because I think that's a bit difficult to understand without really understanding what an object is, but the notion of a self-contained object is important to address. In procedural programming there basically exists data and functions that work with this data, but the data and functions are typically separate and distinct from one another. With an object, the data (attributes) and functions (methods) are all contained within a single, tidy little software component known as the object. This offers numerous advantages that we'll delve into in a future article.

I'm a Person, Not an Object!
Let's consider another, very commonly used example to shed more light on the concept of objects, and this one you'll probably use more regularly in your applications: a person. A Person object, like the Computer object, also has attributes (for example, first and last name) and things they can do, or methods (for example, "walk"). So while you might not prefer to be thought of as an object, as far as the software world is concerned a person is a rather ideal example of an object. If you don't take too much offense let's proceed with this example for now.

Recalling that the three most important aspects of an object are attributes, methods, and that the object is self-contained, we're now going to look more specifically at how we'd go about modeling a person as an object in our applications. First, let's make a basic list of some of the more important attributes that a person has:

  • first name
  • last name
  • birth date
  • sex
  • height
  • weight
Now, let's make a list of some of the things a person can do. These translate into our methods:
  • walk
  • run
  • sleep
  • work
  • talk
  • write ColdFusion applications
You get the idea. Attributes and methods are what define an object.

A Touch of Class
Earlier I mentioned the term class, and before we go much further we need to touch briefly on what a class is. Now that you understand at least in a basic sense what an object is you'll grasp the concept of class pretty easily. A class can be thought of as a generic version of an object. Continuing with our Person object discussion, think of the Person class as a generic person. You don't know if this person is male or female, young or old, short or tall, it's just a nameless, faceless, abstract person.

In OOP you use this generic Person class as the blueprint for creating specific Person objects. The Person class knows that a person has the attributes and methods listed above but knows nothing specific about a particular person. In other words, the Person class knows that a person has a first name, but it doesn't know any particular person's first name. The Person object will know specific details about a particular person, such as "This particular Person's first name is Matt."

You create a specific Person object, which is also known as an instance of the Person class, by instantiating the class. This is a fancy OO way of saying, "Let's take this generic Person class and make it into a specific Person object." For argument's sake let's assume we want to create a Person object called "matt." (I could always use another one of myself to help me get things done.)

In terms specific to ColdFusion, objects are defined using ColdFusion Components (CFCs). The Person class would be a CFC called Person.cfc. To instantiate this class in ColdFusion, you would either use the cfobject tag or the CreateObject function as follows:

Using the cfobject tag:
<cfobject component="Person" name="matt" />

Using CreateObject (this could be within a cfscript block or you could do this within a
cfset tag as well):
matt = CreateObject("component", "Person");

There are some details you'll need to know regarding where ColdFusion looks to locate your CFCs, but don't concern yourself with the specifics of implementation at the moment. Just repeat this phrase over and over again: "I'm thinking in objects. I'm thinking in objects." We'll get to a specific implementation at the end of this article.

So at this point we have a specific Person object called matt with which we can start working. When the matt object is first created, however, it doesn't necessarily know anything about itself. There are a couple of standard ways to get data into our object. You might think we can just start setting our object's attributes using dot notation as follows:

matt.firstName = "Matt";
matt.lastName = "Woodward";

More Stories By Matthew Woodward

Matt Woodward is Principal Information Technology Specialist with the Office of the Sergeant at Arms at the United States Senate. He was until recently a Web application developer for i2 Technologies in Dallas, Texas. A Macromedia Certified ColdFusion Developer and a member of Team Macromedia, he has been using ColdFusion since 1996. In addition to his ColdFusion work, Matt also develops in Java and PHP.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


IoT & Smart Cities Stories
Nicolas Fierro is CEO of MIMIR Blockchain Solutions. He is a programmer, technologist, and operations dev who has worked with Ethereum and blockchain since 2014. His knowledge in blockchain dates to when he performed dev ops services to the Ethereum Foundation as one the privileged few developers to work with the original core team in Switzerland.
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
Whenever a new technology hits the high points of hype, everyone starts talking about it like it will solve all their business problems. Blockchain is one of those technologies. According to Gartner's latest report on the hype cycle of emerging technologies, blockchain has just passed the peak of their hype cycle curve. If you read the news articles about it, one would think it has taken over the technology world. No disruptive technology is without its challenges and potential impediments t...
If a machine can invent, does this mean the end of the patent system as we know it? The patent system, both in the US and Europe, allows companies to protect their inventions and helps foster innovation. However, Artificial Intelligence (AI) could be set to disrupt the patent system as we know it. This talk will examine how AI may change the patent landscape in the years to come. Furthermore, ways in which companies can best protect their AI related inventions will be examined from both a US and...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Bill Schmarzo, Tech Chair of "Big Data | Analytics" of upcoming CloudEXPO | DXWorldEXPO New York (November 12-13, 2018, New York City) today announced the outline and schedule of the track. "The track has been designed in experience/degree order," said Schmarzo. "So, that folks who attend the entire track can leave the conference with some of the skills necessary to get their work done when they get back to their offices. It actually ties back to some work that I'm doing at the University of San...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...