Object-Oriented Programming in ColdFusion
eBook - ePub

Object-Oriented Programming in ColdFusion

  1. 192 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Object-Oriented Programming in ColdFusion

About this book

In Detail

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.

An introduction to object-oriented programming in ColdFusion

Approach

This book is a fast-paced tutorial to developing ColdFusion applications using an object-oriented programming approach. Complete with code examples that can be altered and applied to your application and careful explanations, this book will guide you through your first interaction with object-oriented programming within your ColdFusion applications.

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 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.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

Information

Object-Oriented Programming in ColdFusion


Table of Contents

Object-Oriented Programming in ColdFusion
Credits
Foreword
About the Author
Acknowledgement
About the Reviewer
Preface
Who this book is for
What this book covers
What you need for this book
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Introducing ColdFusion Components
Why use CFCs?
Grouping your functions
Organizing your components
The ColdFusion component tags
Our first component
Defining a method
Returning the data
ColdFusion 9 scripted components
Creating your object
Restricting your functions to scopes
Using arguments within your methods
The Arguments scope
Redefine the function parameters
Combining your methods
Protecting your local variables
Using the Var scope
Placing your Var scoped variables
Naming your Var scoped variables
Accessing your CFC
Instantiating the object
Using the createObject function
Using the cfobject tag
Using the NEW operator
Using cfinvoke
The cfinvoke tag
Using cfinvokeargument
Using attributes as arguments
Using an argument collection
Passing arguments into an instance method call
As a list
As named values
As an argumentCollection
Arguments in action
Merging your functions into one
Using cfargument to combine your methods
Creating an object constructor
Creating an init() function
The Variables scope
Calling your init() function
The This scope
Summary
2. Effective Component Development
Pseudo-constructors
Using the pseudo method
Suppressing whitespace
Output attribute
Pseudo-constructor or init() method
Returning values and variables
returnType
Access properties
Private
Package
Public
Remote
Getting information about your CFC
Introspection
CFC Explorer
Component Doc
Document your code
Benefits of documentation
Displayname attribute
Hint attribute
Description attribute
User-defined metadata
Obtaining CFC metadata
getMetaData
getComponentMetaData
Returning metadata
Detailed introspection
Summary
3. Building Your First Bean
What is a Bean?
But what is it really?
The benefit of using beans
Creating our first Bean
An introduction to UML
Person object in UML
What makes a Bean a Bean
A default/no-argument constructor
Easily accessible for introspection
Setters/Mutators
Getters/Accessors
Completing our Projects Bean
Calling our project Bean
Populating the Bean
Read/Write Bean
Read-only Bean
Helpful objects
Implicit accessors
Summary
4. Inheritance and Object-Oriented Concepts
What is Inheritance?
Avoiding code duplication
Inheriting our products
The Super keyword
Overriding methods
Instantiating our products
The inheritance hierarchy
Specialization
The "IS A" relationship
Polymorphism
Composition
The "HAS A" Relationship
Implied ownership
Aggregation
Summary
5. Data Access Objects
What is a Data Access Object?
Creating a Data Access Object
The create method
Storing a new user
The read method
Handling select results
The update method
The delete method
An alternative save method
The save method
The exists method
Caching the Data Access Objects
Dependency Injection
Summary
6. Gateways
What is a Gateway?
A typical ColdFusion Gateway
Creating a Gateway object
Naming conventions
Adding gateway methods
Minimising code duplication
Revising the gateway object
Caching the Gateway object
The Gateway discussion
No hard and fast rules
Table Data Gateway
Similarities to Data Access Objects
Combining the two patterns
Which option is best?
Summary
7. Creating a Service Layer
What is a Service Layer?
Facade patterns in a nutshell
Creating a service
Defining the User Service
Adding the CRUD methods
Adding the Gateway methods
Adding an abstract class
Defining the address service
onApplicationStart (revisited)
Summary
Index

Object-Oriented Programming in ColdFusion

Copyright © 2009 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: October 2010
Production Reference: 1081010
Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK.
ISBN 978-1-847196-32-3
www.packtpub.com
Cover Image by Filippo ( )

Credits

Author
Matt Gifford
Reviewer
Raymond Camden
Acquisition Editor
David Barnes
Development Editor
Dhiraj Chandiramani
Rakesh Shejwal
Technical Editor
Arun Nadar
Copy Editor
Laxmi Subramanian
Indexer
Rekha Nair
Editorial Team Leader
Aditya Belpathak
Project Team Leader
Priya Mukherji
Project Coordinator
Leena Purkait
Proofreader
Lynda Sliwoski
Production Coordinator
Alwin Roy
Cover Work
Alwin Roy

Foreword

ColdFusion Components (or CFCs) were introduced in ColdFusion MX back in 2002, and since then they have become one of the most important and fundamental building blocks for ColdFusion developers. In fact, recent releases of ColdFusion have made CFC use mandatory, by introducing features that are only available through ColdFusion Components.
As you'd expect from ColdFusion, CFCs are easy to learn and even easier to use. But the beautiful simplicity of ColdFusion Components hides a powerful, sophisticated, and proven Java-based framework on which developers can build highly scalable and manageable applications. Like all ColdFusion features, CFCs can be as simple or as sophisticated as your application requires, and developers can start reaping their benefits easily and painlessly, adding functionality and complexity later as needed.
But this duel personality, highly accessible simplicity on the one hand and all that power on the other, has proven to be a bit of a double-edged sword. The same ease of use that makes ColdFusion so easy to learn and so productive, also makes it too easy to never fully explore and leverage all that ColdFusion has to offer.
This is why I am so glad to see Matt Gifford's hard work take the form of this book. Matt starts with the basics of ColdFusion Components, but then quickly delves into the subtleties and complexities of using them for object-oriented development, demonstrating both the how's and why's, as well as the tips and tricks needed to truly appreciate how ColdFusion Components can (and should) change the way you build your next ColdFusion application.
Matt, this book is long overdue, and your contribution to the ColdFusion community is greatly appreciated. Thanks!
Ben Forta
Director of Platform Evangelism
Adobe Systems
When you start using ColdFusion components, you know that you're on the right track; you can feel this change at some core, instinctual level as if you're about to embrace something that holds tremendous, yet untapped potential. Unfortunately, your instincts won't take you much further beyond this point. The cold reality is, Object-Oriented Programming (OOP), ...

Table of contents

  1. Object-Oriented Programming in ColdFusion

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Object-Oriented Programming in ColdFusion by Matt Gifford in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming. We have over one million books available in our catalogue for you to explore.