|By Sam Farmer||
|April 13, 2005 12:00 AM EDT||
In any membership organization with many in-house applications, the ability to share members' data among applications is vital. Previously, applications would duplicate functionality or make members leave one application to update their new address. This didn't work well for members, nor was it easy to maintain by developers.
Using a new framework, CFMVC, allowed us to make improvements. Our new membership system will allow our paper submission application to let members change their institution with the same front and back end code the membership application uses.
In developing a new framework we needed it to handle the integration of over twenty different databases and applications, work with multiple developers, have low processing and be straightforward. We achieved it by utilizing the benefits of ColdFusion and the Model-View-Controller (MVC) architecture.
ColdFusionThough it's arguable whether or not ColdFusion is an object-oriented development environment, it does support many object-oriented features and has many constructs that allow developers to reuse code and functionality. ColdFusion Components (CFCs) are ideal for all data interactions and business logic while normal ColdFusion pages, User Defined Functions (UDFs) and Custom Tags are ideal for handling display portions.
All applications, regardless of size, contain the following pieces:
- There will be some way of displaying information to a user - most likely, for ColdFusion developers, via a Web browser.
- Another piece will process any changes the user makes generally by writing to a database.
- A third piece will direct the user to a new item to be displayed.
Model-View-ControllerThe Model-View-Controller (MVC) architecture was designed over 25 years ago by Trygve Reenskaug. Originally designed for Smalltalk programmers, it has been used in many languages from Visual Basic to Java, and is especially common among Object Oriented programmers. Companies embracing it include Apple and IBM.
MVC separates an application into the three pieces or tiers mentioned earlier. What exactly does MVC consist of?
- The model layer handles all core data interaction whether with a database, XML files or any other data store along with other business interactions.
- The view layer displays data to the user.
- Any action the user takes goes through the controller layer, which calls the needed parts of the model layer before calling the next view layer to display.
By combining ColdFusion's best practices and the proven architecture of MVC, a framework emerges that modulizes code and allows for it to be used in multiple applications. (Benoit Hediard also has a similar idea for merging together MVC and CF, see www.benorama.com.)
Tying Together CF and MVCWhere does ColdFusion code live and where does it use components, pages and custom tags?
Most applications use at least one database. The model tier retrieves data from the database, stores this data, and provides functionality for interacting with the database. If your application uses text files or some other data storage mechanism, then your model tier will interact with that entity. My MVC implementation involved creating an entity CFC for each table in the database (for example, PeopleEntity.cfc) that handles select (get), update and insert statements (set) and delete if required. A utility CFC is used when returning multiple records, joining other tables and processing functions that require more than one entity, like adding a new member - which requires inserts into a members and an addresses table. All code in the model layer must be written so it can be reused in other applications and should not use session, application or request variables; rather, values should be passed in via attributes. Other CFCs, to be shared, are also added in the model layer for e-mail, SOAP calls, LDAP, and so on.
Each CFC should be a object and contain only functions (methods) that relate to it. Functions should either perform one action only or be a wrapper function and call other functions.
The view tier is where all display files reside. Custom tags are used extensively for presentation code and can be called from any application if needed. Like the model layer, they must not include session, application or request variables. For some presentation purposes UDFs may also be needed.
We did two things that are not part of MVC but were needed for ColdFusion implementation. First, all forms use the post method and custom tags that contain a form accept two attributes: formAction and formMethod, which are placed in the form to pass data to the correct controller. This allows for calls from anywhere and the capability to post to anywhere. Second, all applications have at least one applicationSkin file (see membershipSkin.cfm) in the view layer to allow for an application appearance to be set. Multiple skins can then be used if, say, an admin version is intended to look different to a normal version.
The controller tier is on the web root and has no pretense of being reused. Indeed they should only be used by the application. There are two types of controller files: view-controller and model-controller. View-controller files call code in the view tier and sometimes add customization themselves. Model-controller, as the name suggests, handle all interaction with the model layer but it's important to remember that code here is not intended for reuse and extra features for this application can be added for example an e-mail or calling a web service.
As part of the ColdFusion implementation, view-controller files are standard cfm files that call custom tags. Model-controller files are CFCs, are accessed remotely but as are below an Application.cfm (or Application.cfc) file fit into whatever security system an application deploys. Once a model-controller file has finished processing, it uses cflocation to call the next view-controller file to ensure that data is processed only once if a user reloads.
If you have trouble separating your files into their appropriate areas of the MVC framework, the code in that file is probably doing too much. Try breaking it down into smaller parts.
Folder StructureWhere does all this code sit? As controller files are used only by the application they all belong in the application web root, i.e. webroot/membership/. View-controller files, one for each area of the application, sit in this folder (see Figure 1). This allows for freedom in naming and short URL's. Features that apply to that area only, such as navigation, can also be added easily. Model-controller files are all placed in a controller folder i.e. webroot/membership/controller/.
The rest of our code, in the model and view tiers, is intended to be shared. Below the webroot we set up a folder called cfshare and within that a CFC, tag, and UDF folder (see Figure 2). A merging of ColdFusion, MVC and our desire to share code amongst applications led to such a folder set up. All model files are CFCs leading to a natural home for them, so beneath the CFC folder an additional folder is created for each application to store Entity, Utility and other components.
A similar set-up occurs for view files, all of which are custom tags. Likewise within the tag folder is an additional folder for each application. For the times when UDFs are used they follow the exact same structure under the UDF folder.
To make accessing easier in our code, a ColdFusion mapping is set up to the cfshare folder. Once achieved to access the peopleEntity in the model tier simply call the component:
<cfinvoke component="cfshare.cfc.membership.peopleEntity" method="init"></cfinvoke>
And to access the applicationSkin (using CFMX 6.1):
<cfimport prefix="/cfshare/tag/membership/ " taglib="view"> <view:membershipSkin> </view:membershipSkin>
Or for 6 and backwards:
CodeLet's look at two code examples, which can be downloaded from www.sys-con.com/coldfusion/sourcec.cfm; first the display page for a member to join and second the processing of the collected data.
Code Example One: index.cfm
The first example uses a view-controller called index.cfm.
We start by importing a taglib and giving the prefix of view to enable the calling of custom tags (such a method shows future developers exactly where the custom tag is). Then we param the URL display to a default value of "join". Next we open up the membershipSkin call inside of which is a cfswitch statement which will call the desired display. The default value of join is picked and the "people" custom tag is called with some variables passed in. The cfswitch statement and membershipSkin custom tags are then closed.
Let's step back and look at the people custom tag. First it performs a check to see if it has already been called and if so exits, to prevent duplicate output. Then it calls the peopleEntity cfc and outputs a simple form to allow for the collecting or editing of data. The three attributes it accepts are important: nextAction and nextMethod work in tandem - nextAction contains the path to the processing controller ("controller/membershipController.cfc" in this case) and nextMethod is the name of the function that will be called in the controller file. Passing in a value of -1 for peopleID allows for blank values to be created, but if a value of a real member had been passed in then those values would have been displayed.
Code Example Two: process-controller
How does this get processed? This is an example of a process-controller with the membershipController.cfc being called.
The nextMethod attribute in the people custom tag was set to a hidden field called method which when passed to a cfc remotely will trigger that a function of the provided name. For this example it is join. The access attribute in join function is set to remote to allow for it to be called over the web. The function creates an object to the peopleEntity in the model layer and then calls the set function with the passed in values. The peopleEntity then either runs an update if a valid peopleID is passed or an insert. Just like that, we have a new member! The join function then uses cflocation to relocate the user to the next page.
SummaryThe CFMVC framework discussed above is based on a proven, successful architecture in MVC and has a low processing overhead for ColdFusion. The effect of splitting an application into tiers - model, view and controller - allows us to write applications that can share both data and functionality easily. But the benefits will also extend to completely standalone applications.
|David Hardwick 05/12/05 12:00:44 PM EDT|
Have you investigated the other MVC frameworks before coming up with your own? Mach-II and Tartan for example? I'm using Mach-II on a project right now, and it is very solid. I've worked with Java-based MVC frameworks prior to this project, and I am very impressed with the thought that went into this architecture.
While it is admirable that you put together your own MVC framework, I would rather the CF community do a better job than say the PHP community in putting our efforts behind one or two horses instead of fragmenting our time across multiple 're-inventing the wheel' efforts.
|Sridhar Loka 05/12/05 11:53:07 AM EDT|
I have implemented MVC architecture for ColdFusion application using different approach.
|Jim Davis 05/12/05 07:20:35 AM EDT|
I like this approach and its clear division between layers. Will definitely keep it in mind when picking a methodology for a new project.
|Brian Kotek 05/11/05 07:04:17 PM EDT|
While it is always great to spread the word about best practices and patterns like MVC, I have to point out that using MVC with ColdFusion has been around for years. There are several widely-used frameworks with established communities that support MVC development. Fusebox 4, Mach-II, and Model-Glue are among the most popular. These have the added benefit of a built-in system to handle content elements and layouts without having to resort to custom tags. I would urge anyone interested in this topic to investigate these popular frameworks.
Sensor-enabled things are becoming more commonplace, precursors to a larger and more complex framework that most consider the ultimate promise of the IoT: things connecting, interacting, sharing, storing, and over time perhaps learning and predicting based on habits, behaviors, location, preferences, purchases and more. In his session at @ThingsExpo, Tom Wesselman, Director of Communications Ecosystem Architecture at Plantronics, will examine the still nascent IoT as it is coalescing, including what it is today, what it might ultimately be, the role of wearable tech, and technology gaps stil...
May. 23, 2015 06:00 AM EDT Reads: 4,354
One of the biggest impacts of the Internet of Things is and will continue to be on data; specifically data volume, management and usage. Companies are scrambling to adapt to this new and unpredictable data reality with legacy infrastructure that cannot handle the speed and volume of data. In his session at @ThingsExpo, Don DeLoach, CEO and president of Infobright, will discuss how companies need to rethink their data infrastructure to participate in the IoT, including: Data storage: Understanding the kinds of data: structured, unstructured, big/small? Analytics: What kinds and how responsiv...
May. 23, 2015 06:00 AM EDT Reads: 4,461
Today’s enterprise is being driven by disruptive competitive and human capital requirements to provide enterprise application access through not only desktops, but also mobile devices. To retrofit existing programs across all these devices using traditional programming methods is very costly and time consuming – often prohibitively so. In his session at @ThingsExpo, Jesse Shiah, CEO, President, and Co-Founder of AgilePoint Inc., discussed how you can create applications that run on all mobile devices as well as laptops and desktops using a visual drag-and-drop application – and eForms-buildi...
May. 23, 2015 06:00 AM EDT Reads: 5,409
Advanced Persistent Threats (APTs) are increasing at an unprecedented rate. The threat landscape of today is drastically different than just a few years ago. Attacks are much more organized and sophisticated. They are harder to detect and even harder to anticipate. In the foreseeable future it's going to get a whole lot harder. Everything you know today will change. Keeping up with this changing landscape is already a daunting task. Your organization needs to use the latest tools, methods and expertise to guard against those threats. But will that be enough? In the foreseeable future attacks w...
May. 23, 2015 05:00 AM EDT Reads: 5,669
17th Cloud Expo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Meanwhile, 94% of enterprises are using some form of XaaS – software, platform, and infrastructure as a service.
May. 23, 2015 05:00 AM EDT Reads: 2,405
Cloud is not a commodity. And no matter what you call it, computing doesn’t come out of the sky. It comes from physical hardware inside brick and mortar facilities connected by hundreds of miles of networking cable. And no two clouds are built the same way. SoftLayer gives you the highest performing cloud infrastructure available. One platform that takes data centers around the world that are full of the widest range of cloud computing options, and then integrates and automates everything. Join SoftLayer on June 9 at 16th Cloud Expo to learn about IBM Cloud's SoftLayer platform, explore se...
May. 23, 2015 04:45 AM EDT Reads: 3,094
15th Cloud Expo, which took place Nov. 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA, expanded the conference content of @ThingsExpo, Big Data Expo, and DevOps Summit to include two developer events. IBM held a Bluemix Developer Playground on November 5 and ElasticBox held a Hackathon on November 6. Both events took place on the expo floor. The Bluemix Developer Playground, for developers of all levels, highlighted the ease of use of Bluemix, its services and functionality and provide short-term introductory projects that developers can complete between sessions.
May. 23, 2015 04:00 AM EDT Reads: 6,231
The 3rd International @ThingsExpo, co-located with the 16th International Cloud Expo – to be held June 9-11, 2015, at the Javits Center in New York City, NY – is now accepting Hackathon proposals. Hackathon sponsorship benefits include general brand exposure and increasing engagement with the developer ecosystem. At Cloud Expo 2014 Silicon Valley, IBM held the Bluemix Developer Playground on November 5 and ElasticBox held the DevOps Hackathon on November 6. Both events took place on the expo floor. The Bluemix Developer Playground, for developers of all levels, highlighted the ease of use of...
May. 23, 2015 04:00 AM EDT Reads: 3,389
The explosion of connected devices / sensors is creating an ever-expanding set of new and valuable data. In parallel the emerging capability of Big Data technologies to store, access, analyze, and react to this data is producing changes in business models under the umbrella of the Internet of Things (IoT). In particular within the Insurance industry, IoT appears positioned to enable deep changes by altering relationships between insurers, distributors, and the insured. In his session at @ThingsExpo, Michael Sick, a Senior Manager and Big Data Architect within Ernst and Young's Financial Servi...
May. 23, 2015 04:00 AM EDT Reads: 4,812
In the consumer IoT, everything is new, and the IT world of bits and bytes holds sway. But industrial and commercial realms encompass operational technology (OT) that has been around for 25 or 50 years. This grittier, pre-IP, more hands-on world has much to gain from Industrial IoT (IIoT) applications and principles. But adding sensors and wireless connectivity won’t work in environments that demand unwavering reliability and performance. In his session at @ThingsExpo, Ron Sege, CEO of Echelon, will discuss how as enterprise IT embraces other IoT-related technology trends, enterprises with i...
May. 23, 2015 03:00 AM EDT Reads: 4,273
Enthusiasm for the Internet of Things has reached an all-time high. In 2013 alone, venture capitalists spent more than $1 billion dollars investing in the IoT space. With "smart" appliances and devices, IoT covers wearable smart devices, cloud services to hardware companies. Nest, a Google company, detects temperatures inside homes and automatically adjusts it by tracking its user's habit. These technologies are quickly developing and with it come challenges such as bridging infrastructure gaps, abiding by privacy concerns and making the concept a reality. These challenges can't be addressed w...
May. 23, 2015 02:45 AM EDT Reads: 6,667
We’re no longer looking to the future for the IoT wave. It’s no longer a distant dream but a reality that has arrived. It’s now time to make sure the industry is in alignment to meet the IoT growing pains – cooperate and collaborate as well as innovate. In his session at @ThingsExpo, Jim Hunter, Chief Scientist & Technology Evangelist at Greenwave Systems, will examine the key ingredients to IoT success and identify solutions to challenges the industry is facing. The deep industry expertise behind this presentation will provide attendees with a leading edge view of rapidly emerging IoT oppor...
May. 23, 2015 02:30 AM EDT Reads: 4,916
The industrial software market has treated data with the mentality of “collect everything now, worry about how to use it later.” We now find ourselves buried in data, with the pervasive connectivity of the (Industrial) Internet of Things only piling on more numbers. There’s too much data and not enough information. In his session at @ThingsExpo, Bob Gates, Global Marketing Director, GE’s Intelligent Platforms business, to discuss how realizing the power of IoT, software developers are now focused on understanding how industrial data can create intelligence for industrial operations. Imagine ...
May. 23, 2015 02:00 AM EDT Reads: 5,175
SYS-CON Events announced today that Liaison Technologies, a leading provider of data management and integration cloud services and solutions, has been named "Silver Sponsor" of SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York, NY. Liaison Technologies is a recognized market leader in providing cloud-enabled data integration and data management solutions to break down complex information barriers, enabling enterprises to make smarter decisions, faster.
May. 23, 2015 01:30 AM EDT Reads: 5,305
The 17th International Cloud Expo has announced that its Call for Papers is open. 17th International Cloud Expo, to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, APM, APIs, Microservices, Security, Big Data, Internet of Things, DevOps and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal today!
May. 23, 2015 01:15 AM EDT Reads: 4,263
Collecting data in the field and configuring multitudes of unique devices is a time-consuming, labor-intensive process that can stretch IT resources. Horan & Bird [H&B], Australia’s fifth-largest Solar Panel Installer, wanted to automate sensor data collection and monitoring from its solar panels and integrate the data with its business and marketing systems. After data was collected and structured, two major areas needed to be addressed: improving developer workflows and extending access to a business application to multiple users (multi-tenancy). Docker, a container technology, was used to ...
May. 23, 2015 01:00 AM EDT Reads: 1,971
Hadoop as a Service (as offered by handful of niche vendors now) is a cloud computing solution that makes medium and large-scale data processing accessible, easy, fast and inexpensive. In his session at Big Data Expo, Kumar Ramamurthy, Vice President and Chief Technologist, EIM & Big Data, at Virtusa, will discuss how this is achieved by eliminating the operational challenges of running Hadoop, so one can focus on business growth. The fragmented Hadoop distribution world and various PaaS solutions that provide a Hadoop flavor either make choices for customers very flexible in the name of opti...
May. 23, 2015 12:30 AM EDT Reads: 3,754
For years, we’ve relied too heavily on individual network functions or simplistic cloud controllers. However, they are no longer enough for today’s modern cloud data center. Businesses need a comprehensive platform architecture in order to deliver a complete networking suite for IoT environment based on OpenStack. In his session at @ThingsExpo, Dhiraj Sehgal from PLUMgrid will discuss what a holistic networking solution should really entail, and how to build a complete platform that is scalable, secure, agile and automated.
May. 23, 2015 12:00 AM EDT Reads: 4,257
All major researchers estimate there will be tens of billions devices - computers, smartphones, tablets, and sensors - connected to the Internet by 2020. This number will continue to grow at a rapid pace for the next several decades. With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo, June 9-11, 2015, at the Javits Center in New York City. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be
May. 22, 2015 11:30 PM EDT Reads: 1,964
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo in Silicon Valley. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal an...
May. 22, 2015 11:30 PM EDT Reads: 2,630