|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.
The only place to be June 9-11 is Cloud Expo & @ThingsExpo 2015 East at the Javits Center in New York City. Join us there as delegates from all over the world come to listen to and engage with speakers & sponsors from the leading Cloud Computing, IoT & Big Data companies. Cloud Expo & @ThingsExpo are the leading events covering the booming market of Cloud Computing, IoT & Big Data for the enterprise. Speakers from all over the world will be hand-picked for their ability to explore the economic strategies that utility/cloud computing provides. Whether public, private, or in a hybrid form, clo...
Oct. 30, 2014 12:30 PM EDT Reads: 435
SYS-CON Events announces a new pavilion on the Cloud Expo floor where WebRTC converges with the Internet of Things. Pavilion will showcase WebRTC and the Internet of Things. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. 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.
Oct. 30, 2014 12:15 PM EDT Reads: 1,992
SYS-CON Events announced today that Red Hat, the world's leading provider of open source solutions, will exhibit at Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Red Hat is the world's leading provider of open source software solutions, using a community-powered approach to reliable and high-performing cloud, Linux, middleware, storage and virtualization technologies. Red Hat also offers award-winning support, training, and consulting services. As the connective hub in a global network of enterprises, partners, a...
Oct. 30, 2014 12:15 PM EDT Reads: 1,999
As the Internet of Things unfolds, mobile and wearable devices are blurring the line between physical and digital, integrating ever more closely with our interests, our routines, our daily lives. Contextual computing and smart, sensor-equipped spaces bring the potential to walk through a world that recognizes us and responds accordingly. We become continuous transmitters and receivers of data. In his session at Internet of @ThingsExpo, Andrew Bolwell, Director of Innovation for HP’s Printing and Personal Systems Group, will discuss how key attributes of mobile technology – touch input, senso...
Oct. 30, 2014 12:00 PM EDT Reads: 1,628
SYS-CON Events announced today that Gridstore™, the leader in software-defined storage (SDS) purpose-built for Windows Servers and Hyper-V, will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Gridstore™ is the leader in software-defined storage purpose built for virtualization that is designed to accelerate applications in virtualized environments. Using its patented Server-Side Virtual Controller™ Technology (SVCT) to eliminate the I/O blender effect and accelerate applications Gridsto...
Oct. 30, 2014 11:45 AM EDT Reads: 2,396
The Internet of Things (IoT) is making everything it touches smarter – smart devices, smart cars and smart cities. And lucky us, we’re just beginning to reap the benefits as we work toward a networked society. However, this technology-driven innovation is impacting more than just individuals. The IoT has an environmental impact as well, which brings us to the theme of this month’s #IoTuesday Twitter chat. The ability to remove inefficiencies through connected objects is driving change throughout every sector, including waste management. BigBelly Solar, located just outside of Boston, is trans...
Oct. 30, 2014 11:00 AM EDT Reads: 2,086
Connected devices and the Internet of Things are getting significant momentum in 2014. In his session at Internet of @ThingsExpo, Jim Hunter, Chief Scientist & Technology Evangelist at Greenwave Systems, will examine three key elements that together will drive mass adoption of the IoT before the end of 2015. The first element is the recent advent of robust open source protocols (like AllJoyn and WebRTC) that facilitate M2M communication. The second is broad availability of flexible, cost-effective storage designed to handle the massive surge in back-end data in a world where timely analytics...
Oct. 30, 2014 08:00 AM EDT Reads: 1,490
Internet of @ThingsExpo Silicon Valley announced on Thursday its first 12 all-star speakers and sessions for its upcoming event, which will take place November 4-6, 2014, at the Santa Clara Convention Center in California. @ThingsExpo, the first and largest IoT event in the world, debuted at the Javits Center in New York City in June 10-12, 2014 with over 6,000 delegates attending the conference. Among the first 12 announced world class speakers, IBM will present two highly popular IoT sessions, which will take place November 4-6, 2014 at the Santa Clara Convention Center in Santa Clara, Calif...
Oct. 30, 2014 07:30 AM EDT Reads: 2,154
The Internet of Things (IoT) promises to evolve the way the world does business; however, understanding how to apply it to your company can be a mystery. Most people struggle with understanding the potential business uses or tend to get caught up in the technology, resulting in solutions that fail to meet even minimum business goals. In his session at Internet of @ThingsExpo, Jesse Shiah, CEO / President / Co-Founder of AgilePoint Inc., will show what is needed to leverage the IoT to transform your business. He will discuss opportunities and challenges ahead for the IoT from a market and tec...
Oct. 29, 2014 11:00 PM EDT Reads: 1,420
SYS-CON Events announced today that TeleStax, the main sponsor of Mobicents, will exhibit at Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. TeleStax provides Open Source Communications software and services that facilitate the shift from legacy SS7 based IN networks to IP based LTE and IMS networks hosted on private (on-premise), hybrid or public clouds. TeleStax products include Restcomm, JSLEE, SMSC Gateway, USSD Gateway, SS7 Resource Adaptors, SIP Servlets, Rich Multimedia Services, Presence Services/RCS, Diame...
Oct. 29, 2014 05:00 PM EDT Reads: 1,554
From a software development perspective IoT is about programming "things," about connecting them with each other or integrating them with existing applications. In his session at @ThingsExpo, Yakov Fain, co-founder of Farata Systems and SuranceBay, will show you how small IoT-enabled devices from multiple manufacturers can be integrated into the workflow of an enterprise application. This is a practical demo of building a framework and components in HTML/Java/Mobile technologies to serve as a platform that can integrate new devices as they become available on the market.
Oct. 29, 2014 02:15 PM EDT Reads: 2,017
SYS-CON Events announced today that O'Reilly Media has been named “Media Sponsor” of SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. O'Reilly Media spreads the knowledge of innovators through its books, online services, magazines, and conferences. Since 1978, O'Reilly Media has been a chronicler and catalyst of cutting-edge development, homing in on the technology trends that really matter and spurring their adoption by amplifying "faint signals" from the alpha geeks who are creating the future. An...
Oct. 29, 2014 01:00 PM EDT Reads: 1,500
SYS-CON Events announced today that Aria Systems, the recurring revenue expert, has been named "Bronze Sponsor" of SYS-CON's 15th International Cloud Expo®, which will take place on November 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Aria Systems helps leading businesses connect their customers with the products and services they love. Industry leaders like Pitney Bowes, Experian, AAA NCNU, VMware, HootSuite and many others choose Aria to power their recurring revenue business and deliver exceptional experiences to their customers.
Oct. 29, 2014 10:00 AM EDT Reads: 2,072
The Transparent Cloud-computing Consortium (abbreviation: T-Cloud Consortium) will conduct research activities into changes in the computing model as a result of collaboration between "device" and "cloud" and the creation of new value and markets through organic data processing High speed and high quality networks, and dramatic improvements in computer processing capabilities, have greatly changed the nature of applications and made the storing and processing of data on the network commonplace.
Oct. 29, 2014 10:00 AM EDT Reads: 2,009
The Internet of Things (IoT) is going to require a new way of thinking and of developing software for speed, security and innovation. This requires IT leaders to balance business as usual while anticipating for the next market and technology trends. Cloud provides the right IT asset portfolio to help today’s IT leaders manage the old and prepare for the new. Today the cloud conversation is evolving from private and public to hybrid. This session will provide use cases and insights to reinforce the value of the network in helping organizations to maximize their company’s cloud experience.
Oct. 29, 2014 09:00 AM EDT Reads: 2,037
As a disruptive technology, Web Real-Time Communication (WebRTC), which is an emerging standard of web communications, is redefining how brands and consumers communicate in real time. The on-going narrative around WebRTC has largely been around incorporating video, audio and chat functions to apps. In his session at Internet of @ThingsExpo, Alex Gouaillard, Founder and CTO of Temasys Communications, will look at a fourth element – data channels – and talk about its potential to move WebRTC beyond browsers and into the Internet of Things.
Oct. 29, 2014 08:00 AM EDT Reads: 1,578
SYS-CON Events announced today that Gigaom Research has been named "Media Sponsor" of SYS-CON's 15th International Cloud Expo®, which will take place on November 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Ashar Baig, Research Director, Cloud, at Gigaom Research, will also lead a Power Panel on the topic "Choosing the Right Cloud Option." Gigaom Research provides timely, in-depth analysis of emerging technologies for individual and corporate subscribers. Gigaom Research's network of 200+ independent analysts provides new content daily that bridges the gap between break...
Oct. 28, 2014 11:45 PM EDT Reads: 1,596
We certainly live in interesting technological times. And no more interesting than the current competing IoT standards for connectivity. Various standards bodies, approaches, and ecosystems are vying for mindshare and positioning for a competitive edge. It is clear that when the dust settles, we will have new protocols, evolved protocols, that will change the way we interact with devices and infrastructure. We will also have evolved web protocols, like HTTP/2, that will be changing the very core of our infrastructures. At the same time, we have old approaches made new again like micro-services...
Oct. 28, 2014 03:00 PM EDT Reads: 1,558
The Industrial Internet revolution is now underway, enabled by connected machines and billions of devices that communicate and collaborate. The massive amounts of Big Data requiring real-time analysis is flooding legacy IT systems and giving way to cloud environments that can handle the unpredictable workloads. Yet many barriers remain until we can fully realize the opportunities and benefits from the convergence of machines and devices with Big Data and the cloud, including interoperability, data security and privacy.
Oct. 28, 2014 12:00 PM EDT Reads: 1,923
Swiss innovators dizmo Inc. launches its ground-breaking software, which turns any digital surface into an immersive platform. The dizmo platform seamlessly connects digital and physical objects in the home and at the workplace. Dizmo breaks down traditional boundaries between device, operating systems, apps and software, transforming the way users work, play and live. It supports orchestration and collaboration in an unparalleled way enabling any data to instantaneously be accessed on any surface, anywhere and made interactive. Dizmo brings fantasies as seen in Sci-fi movies such as Iro...
Oct. 28, 2014 10:00 AM EDT Reads: 2,115