Whatever message this page gives is out now! Go check it out!
// myAbstractClass.cfc
abstract component {
// abstract methods
// concrete methods
}myClassInstance=new myAbstractComponent();abstract component Shape{
abstract function draw();
}component Square extends="Shape" {
function draw() {
writeoutput("Inside Square::draw() method. <br/>");
}
}component ShapeFactory extends="AbstractFactory" {
Shape function getShape(String shapeType){
if(shapeType EQ "RECTANGLE"){
return new Rectangle();
}else if(shapeType EQ "SQUARE"){
return new Square();
}else
return "not defined";
}
}component Rectangle extends="Shape" {
function draw() {
writeoutput("Inside Rectangle::draw() method. <br/>");
}
}abstract component AbstractFactory {
abstract Shape function getShape(String shape) ;
}component FactoryProducer {
AbstractFactory function getFactory(String choice){
if(choice eq "SHAPE"){
return new ShapeFactory();
}
}
}<cfscript>
//get shape factory
shapeFactory = new FactoryProducer().getFactory("SHAPE");
//get an object of Shape Rectangle
shape2 = new shapeFactory().getShape("RECTANGLE");
//call draw method of Shape Rectangle
shape2.draw();
//get an object of Shape Square
shape3 = new shapeFactory().getShape("SQUARE");
//call draw method of Shape Square
shape3.draw();
</cfscript>component{
final max=100;
function mymethod(){
//max=100;
writeoutput("final variable is: " & max);
}
}component{
final max;
// constructor
function mymethod(){
max=50;
writeoutput("final variable is: " & max);
}
}final component{
// define methods
}public final void function myMethod() {
// method body
}final component {
}component extends=”A” {
}component {
// final method and cannot be overridden
public final void function display(){
writeOutput("From super class, final display() method");
}
// concrete method
public void function show(){
writeOutput("From super class, non-final show() method");
}
}component extends="Test"{
//public void function display(){}
public void function show()
{
writeOutput("From subclass show() method");
}
}<cfscript>
d1=new Demo();
d1.display();
d1.show();
</cfscript>component{
public static final any function calculateCircumference(radius) {
var PI = 3.141592653589793;
return 2 * PI * radius;
}
}<cfscript>
writeOutput(utils::calculateCircumference(5))
</cfscript>interface {
public default any function returnsany(any obj)
{
return obj;
}
}component implements="I"
{
}<cfscript>
myobj=new Comp();
writeOutput(myobj.returnsany("hello world"));
</cfscript>interface displayName="IAnimal" hint="Animal Interface."{
any function eat(any prey="");
any function makeNoise(string noise);
}component implements="IAnimal" displayname="Animal"{
property animalSize;
property animalType;
function init(animalSize,animalType){
variables.instance.animalSize = arguments.animalSize
variables.instance.animalType = arguments.animalType
}
Animal function eat(any prey=""){
return prey;
}
string function makeNoise(string noise){
return noise;
}
function getanimalSize(){
return variables.instance.animalSize
}
function getanimalType(){
return variables.instance.animalType
}
}<cfscript>
bunny=new Animal('small','rabbit');
simba =new Animal('large','Tiger');
writeoutput("Simba eats " & simba.eat(bunny).getAnimaltype() & "<br/>");
writeoutput("Simba " & simba.makenoise('roarsss'));
</cfscript>