Book Image

Object-Oriented Programming in ColdFusion

By : Matthew Gifford
Book Image

Object-Oriented Programming in ColdFusion

By: Matthew Gifford

Overview of this book

Are you tired of procedural programming or is your extensive code base starting to become un-manageable? Breathe some new life into your code and improve your development skills with the basic concepts of object-oriented programming. Utilize objects, modular components, and design patterns to expand your skills and improve your ColdFusion applications. Packed with example code, and written in a friendly, easy-to-read style, this book is just what you need if you are serious about ColdFusion.This book is a fast-paced tutorial to important ColdFusion object-oriented programming topics. It will give you clear, concise, and practical guidance to take you from the basics of ColdFusion to the skills that will make you a ColdFusion developer to be reckoned with. Don't be put off by jargon or complex diagrams; read and see how you can benefit from this book and extend your development skills in the process.Using the practical examples within this guide, you will learn how to structure your applications and code, applying the fundamental basics of object-oriented programming to develop modular, reusable components that will scale easily with your application. You will learn the basic fundamental practices of object-oriented programming, from object creation and re-use, to Bean objects, service layers, Data Access objects, and sample design patterns to gain a better understanding of OOP using examples that can be altered and applied in your application. Complete with detailed code samples and snippets, and written in a friendly easy-to-follow style, you will be able to break free from writing purely procedural code and enhance your applications by building structured applications utilizing basic design patterns and object-oriented principles.
Table of Contents (14 chapters)
Object-Oriented Programming in ColdFusion
Credits
Foreword
About the Author
Acknowledgement
About the Reviewer
Preface

Preface

The principles and fundamental elements of Object-Oriented Programming (OOP) are not new to the development world, although for some, there is a hesitancy to engage with OOP as it can be perceived as a confusing or unnecessary method of development.

As you read Object-Oriented Programming in ColdFusion, you will be guided through the core structure of ColdFusion Components, the foundation of OOP in CFML-based applications, and an introduction to some common design patterns and principles used in object-oriented development.

This book deals with the basic fundamental practices of OOP, including object creation and reuse, Bean objects, service layers, Data Access Objects, and simple design patterns. This is intended to help the reader gain a better understanding of OOP using examples that can be altered and applied into any application.

Object-Oriented Programming in ColdFusion aims to simplify the understanding of OOP, and dispense with unnecessary jargon and complex diagrams. By taking this more direct approach, this book aims to assist the reader in understanding the principles of OOP, how to implement them into their ColdFusion applications, and help the user extend their development skills in the process.

Using the practical examples within this easy-to-follow guide, you will learn how to structure your applications and code, and apply the fundamental basics of OOP to develop modular and reusable components that will scale easily with your application. This is ideal for any ColdFusion developer looking to break free from writing purely procedural code, and extend and advance their development practices.

Who this book is for

If you are a web developer wanting to implement object-oriented programming with ColdFusion, then this book is for you. If your goal is to get a good grounding in the basics of the object-oriented programming concepts, this book is perfect for you. No prior knowledge of object-oriented programming is expected, but basic knowledge of ColdFusion development skills is assumed.

What this book covers

Chapter 1, Introducing ColdFusion Components outlines the basic elements of ColdFusion Components. The reader is guided through the structure of a CFC, arguments, parameters, and encapsulating information.

Chapter 2, Effective Component Development highlights some important attributes and techniques to optimize your component's output. We also investigate introspecting a component as well as providing and reading metadata.

Chapter 3, Building Your First Bean begins the reader's journey into object-oriented development. This chapter focuses on a Bean object, understanding requirements and benefits for using one, and how to set and access properties within the Bean.

Chapter 4, Inheritance and Object-Oriented Concepts starts to explore the world of object-oriented programming in a little more detail. This chapter also introduces some key concepts such as polymorphism and composition.

Chapter 5, Data Access Objects looks at the use of Data Access Objects to access and obtain information from a data source. We'll also look at persisting objects in memory throughout your application.

Chapter 6, Gateways introduces an optional data access method for use in your object-oriented development, and also highlights some extra benefits of code separation to help enable easier code management within your applications.

Chapter 7, Creating a Service Layer introduces the use of facade objects to your application's underlying API / component structure. We also explore object inheritance and options to streamline the existing code within your framework.

What you need for this book

To get the most out of this publication, you will require version 8 or 9 of the ColdFusion server. You will also need a SQL database such as SQL server or MySQL to create a database to run the code examples.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Let's take a look at the onApplicatonStart() method as it currently stands within the Application.cfc file."

A block of code is set as follows:

<cfscript>
objProjects = createObject("component", "com.projects.Projects");
</cfscript>
<cfoutput>
The current date is #objProjects.getCurrentDate()#
</cfoutput>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<cffunction name="getAllUsers" access="public" output="false" hint="I run a query of all users within the database table.">
<!--- Call the query method from the User Gateway and return the query object. --->
<cfreturn variables.instance.userGW.filterAllUsers() />
</cffunction>

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen".

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to, and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Note

Downloading the example code for this book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books maybe a mistake in the text or the code we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.