Last updated
Ortus Solutions, Corp
Last updated
The abstract constructs can be both used in Lucee and Adobe 2018. The main goal of abstraction is to handle complexities by hiding/encapsulating unnecessary details from other users. Abstraction is implemented in most languages by defining a class that has methods, properties & constructors.
Abstract will allow you to define two contexts of operation:
Components
Functions
An abstract component allows you to make a template or blueprint for a component that will be eventually inherited from, so the inheriting class doesn't have to implement all of the methods. Therefore, abstract classes cannot be instantiated but only extended.
We would suggest that if you define abstract components that you add the prefix Abstract
to the component name as best practice: AbstractAnimal, AbstractLogger, AbstractPerson
. This goes a long way to help with readability and standards.
In an inheritance hierarchy the first non-abstract class should implement all the abstract methods.
As you can see from the example above, abstract functions can be defined ONLY in an abstract component. These functions are demarcated as abstract so inherited components can implement them. You can have many abstract functions in your abstract component and you can also have many concrete functions as well:
Only abstract components can contain abstract functions.
Abstract classes can have both abstract and concrete methods defined within it. Abstract methods have no body, they are just declared, much like interfaces. Usually, you would do this to satisfy an interface declaration. In my years of experience, abstract classes usually go hand in hand with interfaces and usually implement .