In object-oriented programming, a God object is an object that knows too much or does too much. The God object is an example of an anti-pattern. A common programming technique is to separate a large problem into several smaller problems (a divide and conquer strategy) and create solutions for each of them. - https://en.wikipedia.org/wiki/God_object
accessorsin the component definition denotes that automatic getters (accessors) and setters (mutators) will be created for all defined properties in the object. Also notice that the component and each property can be documented using
/** **/notation, which is great for automatic documentation generators like DocBox.
createObject()keyword operation from another file, which can be a template or yet another component.
newkeyword will automatically call an object's constructor: the
createObject()will not, you will have to call the constructor manually:
thisscope. This is a reference of the object itself that is returned. You can also return
thisfrom ANY other function which allows for expressive or fluently chainable methods.
new Object()operator, the Object's
init()function will be called for you automatically. If you use the
init()is NOT called automatically for you, you will call it explicitly.
cfcomponentdeclaration and the first function is considered to be the pseudo-constructor. This area of execution will be executed for you implicitly whenever the object is created, even before the implicit
init()method call. I know confusing, but here is a simple sequence:
new()/createObject() -> pseudo-constructor -> init()
variables- Private scope, visible internally to the CFC only, where all
propertiesare placed in by default. Public and private function references are place here as well.
this- Public scope, visible from the outside world (can break encapsulation) public function references are placed here.
static- Same as in Java, ability to staticly declare variables and functions at the blueprint level and not at the instance level. (Lucee only)
componentconstruct can also have many attributes or name-value pairs that will give it some extra functionality for SOAP/REST web services and for Hibernate ORM Persistence. Each CFML engine provides different capabilities. You can find all of them here: https://cfdocs.org/cfcomponent. Below are the most common ones:
accessors- Enables automatic getters/setters for properties
extends- Provides inheritance via the path of the Component (CFC)
implements- Names of the interfaces it implements
persistent- Makes the object a Hibernate Entity which can be fine tuned through a slew of other attributes.
serializable- Whether the component can be serialized into a string/binary format or not. Default is