Introduction to Object Oriented Programming in ColdFusion Nicholas Tunney Senior Software Architect
Why Am I Listening to This Guy? Experience Credentials –Articles and Whitepapers –Presentations –Adobe Community Expert –Adobe Certified Advanced ColdFusion Developer –Adobe Certified Instructor Current Projects
What will we cover? Why use Object Oriented concepts? Introduction to Object Oriented Programming How to apply Object Oriented principles to ColdFusion Samples Q and A
Why use Object Oriented Concepts Scalability Uniformity Reusability Maintainability
Introduction to Object Oriented Programming History (Bar trivia) –Simula I and Simula 67 (early 60s) –SmallTalk used Simula concepts (early 70s) Abstract datatypes Concurrent program execution Integrated GUIs –C++ and Java
Introduction to Object Oriented Programming ColdFusion is not pure OO! –Pure OO languages treat everything in the language as an object –ColdFusion allows us to use tools within the language that apply OO concepts, but does not require the use of objects –Constructors, Overloading –“Java Lite", Rails.
Introduction to Object Oriented Programming OO is not a language or a framework –Principles –Best Practices –Patterns
Introduction to Object Oriented Programming Class –Properties –Constructor –Accessors/Mutators –Object Methods –Sometimes Data Access (CRUD)
Introduction to Object Oriented Programming Object –Instantiated class –Real world entity
Introduction to Object Oriented Programming Defining an object - “Be” the object –Who can I talk to? –Who do I depend on? –What can I do?
Introduction to Object Oriented Programming Encapsulation –Private properties –Accessors/Mutators –Good API defines the object. –Over Engineering
Introduction to Object Oriented Programming Polymorphism –One class, many instantiations –Employee class Manager Accountant Programmer
Introduction to Object Oriented Programming Inheritance and Composition –The “is a” “has a” paradigm Employee –Employee has a(n) address –Manager is a(n) employee –“Favor Composition”
Introduction to Object Oriented Programming Q & A
Applying Object Oriented Principles to ColdFusion Creating a class – … properties … … constructor … … accessors/mutators … … public methods … … private methods …
Applying Object Oriented Principles to ColdFusion Creating a class – Properties variables.id = 0; variables.firstName = “”; … -- OR – …
Applying Object Oriented Principles to ColdFusion Creating a class – Constructor …
Applying Object Oriented Principles to ColdFusion Creating a class – Accessor (“Getter”) … calculations …
Applying Object Oriented Principles to ColdFusion Creating a class – Mutator (“Setter”) … calculations …
Applying Object Oriented Principles to ColdFusion Creating a class – public and private methods –Data Access – CRUD –The “What can I do” of the object
Applying Object Oriented Principles to ColdFusion Instantiating an object – best practice Example:
Applying Object Oriented Principles to ColdFusion Interacting with properties –Properties are in private scope (encapsulation) –Use accessor/mutator methods
Applying Object Oriented Principles to ColdFusion Persistence Methods –CRUD (Create(), Read(), Update(), Delete()) –Can also be separated out into separate DAO –CRUD can be further encapsulated with commit()
Applying Object Oriented Principles to ColdFusion Gateway Objects –Used for accessing multiple objects or records –For small applications, methods can be put into one main data access object –For large applications, best practice is to move methods into object specific gateways
Conclusion OO is not new, just new to CF CF is not pure OO Classes contain encapsulated properties, accessor and mutator methods, private and public methods Objects are instantiated classes Objects are programmatic representations of real world entities
Conclusion - cont’d Think Objects instead of Relational DB. “Be” the object when defining the class Composition is preferred to inheritance DAO methods may be in the class, or in its own class (CRUD) Gateways access recordsets or multiple objects Code generators can be your best friend!
Q & A
Thanks!