Last active
December 17, 2015 01:39
-
-
Save djleeds/5529833 to your computer and use it in GitHub Desktop.
Demonstrates inheritance, composition, mixins, and patches in ColdFusion. The article that corresponds to these code snippets can be found here:
http://www.hitthebits.com/2013/05/coldfusion-code-reuse.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- EggLayer.cfc ---> | |
<cfcomponent> | |
<cffunction name="layEggs"> | |
<cfargument name="count" /> | |
<cfreturn "I just laid #count# eggs." /> | |
</cffunction> | |
</cfcomponent> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Duck.cfc and Platypus.cfc ---> | |
<cfcomponent extends="EggLayer"> | |
<!--- ...elided... ---> | |
</cfcomponent> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Duck.cfc and Platypus.cfc ---> | |
<cfcomponent> | |
<cfset variables.eggLayer = new EggLayer() /> | |
<cffunction name="layEggs"> | |
<cfargument name="count" /> | |
<cfreturn variables.eggLayer.layEggs(arguments.count) /> | |
</cffunction> | |
</cfcomponent> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- eggLayer.cfm ---> | |
<cffunction name="layEggs"> | |
<cfargument name="count" /> | |
<cfreturn "I just laid #count# eggs." /> | |
</cffunction> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Duck.cfc and Platypus.cfc ---> | |
<cfcomponent> | |
<cfinclude template="eggLayer.cfm" /> | |
<!--- the rest of the class is elided ---> | |
</cfcomponent> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Duck.cfc and Platypus.cfc ---> | |
<cfcomponent> | |
<!--- No change to these files is required ---> | |
</cfcomponent> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- index.cfm, or maybe some factory class ---> | |
<cffunction name="layEggs"> | |
<cfargument name="count" /> | |
<cfreturn "I just laid #count# eggs." /> | |
</cffunction> | |
<cfset duck = new Duck() /> | |
<cfset platypus = new Platypus() /> | |
<cfset duck.layEggs = this.layEggs /> | |
<cfset platypus.layEggs = this.layEggs /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment