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, Adobe Flex

ColdFusion: Article

Don't Talk to Strangers!

ColdFusion components and the Law of Demeter

"Don't talk to strangers" may sound like the advice your mother used to give you as a child, but as is so often the case, mother knows best. As we'll soon see, "don't talk to strangers" or "only talk to your friends" is advice that can apply to programming as well. In programming terms, this general concept is known as the Law of Demeter, and it's a great programming practice that facilitates a reduction in coupling between objects in object-oriented applications.

Before you turn to the next article and dismiss this as applicable to OO programming but having no relevance to your procedural Fusebox application, read on as you'll see that the benefits of the Law of Demeter can easily be gained in any application that uses ColdFusion components (CFCs). By applying the Law of Demeter, you can reduce coupling between your CFCs and make your application more flexible and easy to maintain.

First let's investigate the concept of coupling. Coupling is the degree to which one object is dependent upon another or, in the case of ColdFusion, the degree to which one CFC is dependent upon another CFC. For example, if CFC A is used by CFCs B and C and the CFCs are tightly coupled, a change to CFC A will also likely impact CFCs B and C. Minimizing coupling between CFCs is an important goal as you develop your applications.

Have you ever worked on an application in which you have changed something that appears to be quite a small, isolated part of the system, but changes to this seemingly isolated part result in the application grinding to a halt? Perhaps that's an extreme example, but you don't want to make a change to a ColdFusion component in an application and have it all come crashing down because of the huge amount of dependencies between that component and other components within the application.

Systems that have low coupling reduce the impact of changes, thus making them easier to maintain. We all like things to be easier to maintain, right?

With all this talk of coupling, you may be getting the impression that any coupling whatsoever is a bad thing to have in your application. A key point to remember, however, is that a small amount of coupling is necessary in order for your application to do anything. It is unnecessary coupling that we should strive to avoid. In addition, coupling to stable, well-designed components such as the components in the ColdFusion MX 7 Admin API is generally safe as these are unlikely to change significantly in a way that will break backward compatibility.

As you build CFCs and attempt to avoid unnecessary coupling, it's helpful to think of each CFC as exposing an API to other components in the system. By exposing a public API, each CFC can hide its inner workings from other components so that outside components need only know how to communicate with the CFC, but they don't need to know any of the details related to how the CFC performs its functions.

In ColdFusion, components can be coupled in one of the following ways:

  • If CFC X calls a function on CFC Y, component X is said to be coupled to component Y.
  • If CFC X contains a variable (either in a variables scope or locally inside a function) that is a reference to CFC Y, component X is said to be coupled to component Y.
  • If CFC X extends CFC Y, component X is said to be coupled to component Y.
  • If CFC X receives an instance of CFC Y as an argument to one of its functions or an instance of CFC Y is returned from a function called on another CFC, then...
Well, you're probably starting to get the picture. Recognizing coupling and avoiding unnecessary coupling is an important skill that you'll want to develop as you build your applications.

The Law of Demeter
The Law of Demeter was first defined by Ian Holland while working on The Demeter project at Northeastern University in 1987. In brief, the Law of Demeter states that an object should only call methods that:

  • Belong to itself (i.e., its own methods)
  • Are on objects passed in as a parameter
  • Are on objects created by the object
A full summary of the Law of Demeter can be found at www.cmcrossroads.com/bradapp/docs/demeter-intro.html. Translating this to ColdFusion, this means your component should only call its own functions, functions of components it contains, or functions of components passed in to its own functions. An easier way to remember this is basically a CFC should not call functions on components that are returned from other CFCs. For example, the following violates the Law of Demeter:

<cfset myPostalCode = person.getAddress().getPostCode() />

In the following example, we have a Person CFC that contains an address CFC held internally in the variables scope with a function named getPostCode, and getPostCode returns a postal code. To retrieve the person's postal code we may write something along the lines of this:

<cfset me = createObject("component","person") />
<cfset postcode = me.getAddress().getPostCode() />

Or maybe the following, which is really just a variation of the code above:

<cfset me = createObject("component","person") />
<cfset myHouse = me.getAddress() />
<cfset postcode = myHouse.getPostCode() />


More Stories By Kola Oyedeji

Kola Oyedeji is technical director of Vivid Lime, a London-based full services agency. Prior to that, he was a senior software developer for the Collinson Group, developing Enterprise Loyalty and Insurance Systems. Kola holds a BSc in Computer and Information systems. His blog is available at www.coolskool.blog-city.com.

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.


@ThingsExpo Stories
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...
We are seeing a major migration of enterprises applications to the cloud. As cloud and business use of real time applications accelerate, legacy networks are no longer able to architecturally support cloud adoption and deliver the performance and security required by highly distributed enterprises. These outdated solutions have become more costly and complicated to implement, install, manage, and maintain.SD-WAN offers unlimited capabilities for accessing the benefits of the cloud and Internet. ...
Headquartered in Plainsboro, NJ, Synametrics Technologies has provided IT professionals and computer systems developers since 1997. Based on the success of their initial product offerings (WinSQL and DeltaCopy), the company continues to create and hone innovative products that help its customers get more from their computer applications, databases and infrastructure. To date, over one million users around the world have chosen Synametrics solutions to help power their accelerated business or per...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Founded in 2000, Chetu Inc. is a global provider of customized software development solutions and IT staff augmentation services for software technology providers. By providing clients with unparalleled niche technology expertise and industry experience, Chetu has become the premiere long-term, back-end software development partner for start-ups, SMBs, and Fortune 500 companies. Chetu is headquartered in Plantation, Florida, with thirteen offices throughout the U.S. and abroad.
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...
I think DevOps is now a rambunctious teenager - it's starting to get a mind of its own, wanting to get its own things but it still needs some adult supervision," explained Thomas Hooker, VP of marketing at CollabNet, in this SYS-CON.tv interview at DevOps Summit at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Major trends and emerging technologies – from virtual reality and IoT, to Big Data and algorithms – are helping organizations innovate in the digital era. However, to create real business value, IT must think beyond the ‘what’ of digital transformation to the ‘how’ to harness emerging trends, innovation and disruption. Architecture is the key that underpins and ties all these efforts together. In the digital age, it’s important to invest in architecture, extend the enterprise footprint to the cl...
Data is the fuel that drives the machine learning algorithmic engines and ultimately provides the business value. In his session at Cloud Expo, Ed Featherston, a director and senior enterprise architect at Collaborative Consulting, discussed the key considerations around quality, volume, timeliness, and pedigree that must be dealt with in order to properly fuel that engine.
Two weeks ago (November 3-5), I attended the Cloud Expo Silicon Valley as a speaker, where I presented on the security and privacy due diligence requirements for cloud solutions. Cloud security is a topical issue for every CIO, CISO, and technology buyer. Decision-makers are always looking for insights on how to mitigate the security risks of implementing and using cloud solutions. Based on the presentation topics covered at the conference, as well as the general discussions heard between sessio...
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
No hype cycles or predictions of zillions of things here. IoT is big. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, Associate Partner at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He discussed the evaluation of communication standards and IoT messaging protocols, data analytics considerations, edge-to-cloud tec...
DXWorldEXPO LLC announced today that the upcoming DXWorldEXPO | CloudEXPO New York event will feature 10 companies from Poland to participate at the "Poland Digital Transformation Pavilion" on November 12-13, 2018.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
CloudEXPO | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.