No one seems to have a direct response to your question. I want to tell you that there's a cfc equil. I am not going to type line by line comparision (lazy typing), but you will see enough to get the point.
the player class (cfc as it is referred in cf) would look like this:
// player.cfc
<cfcomponent displayname="Player Class">
<cffunction name="init" access="public" returntype="void">
<cfscript>
//constructor code goes here
// here, i can pull stuff from the database or read from xml file, let's say we pull player id from the database.
variables.firstName=first name value from db;
variables.lastname=last name value from db;
[ etc]
</cfscript>
</cffunction>
<cffunction name="GetFirstName" access="public" returntype="string">
<cfreturn variables.firstName/>
</cffunction>
<cffunction name="GetMiddleName" access="public" returntype="string">
<cfreturn variables.middleName/>
</cffunction>
<cffunction name="GetLastName" access="public" returntype="string">
<cfreturn variables.lastName/>
</cffunction>
<cffunction name="GetAtBats" access="public" returntype="numeric">
<cfreturn variables.atBats/>
</cffunction>
<cffunction name="GetHits" access="public" returntype="numeric">
<cfreturn variables.hits/>
</cffunction>
<cffunction name="GetDoubles" access="public" returntype="numeric">
<cfreturn variables.Doubles/>
</cffunction>
<cffunction name="GetBattingAverage" access="public" returntype="numeric">
<cfset var temp=Round(GetDoubles()*GetAtBats()/GetHist())>
<cfreturn temp/>
</cffunction>
</cfcomponent>
Then, on my calling page (cfm page), I can instanitate the player cfc (class) like this.
<cfset objPlayer=CreateObject("component","[path].player").init([pass in whatever identifer like player id])>
#objPlayer.getLastName()#
objPlayer.getFistName()
objPlayer.getHists()
objPlayer.getDoubles()
objPlayer.GetBattingAverage()
well, you get the point.
| bobum wrote: |
If I have a distorted view of ColdFusion I will admit it. But I still don't see the object lofty.
And I didn't mean to show me how you pull it from the database. Populating the object has nothing to do with the creation of the structure of said object.
Here is a stab at a stubbed version of the player object in C#...
using System;
using System.Collections;
namespace WebApplication1
{
/// <summary>
/// Summary description for player.
/// </summary>
public class player
{
public player()
{
//
// TODO: Add constructor logic here
//
}
private string _firstName;
private string _middleName;
private string _lastName;
private string _lastNameSuffix;
private char _batsHanded;
private char _throwsHanded;
private ArrayList _positionsPlayed;
private int _hits;
private int _atBats;
private int _doubles;
private int _triples;
private int _homeruns;
private int _walks;
private int _strikeouts;
private int _caughtStealing;
private int _stolenBases;
public string FirstName
{
get
{
return _firstName;
}
}
public string MiddleName
{
get
{
return _middleName;
}
}
public string LastName
{
get
{
return _lastName;
}
}
public string LastNameSuffix
{
get
{
return _lastNameSuffix;
}
}
public char BatsHanded
{
get
{
return (char) _batsHanded;
}
}
public char ThrowsHanded
{
get
{
return (char) _throwsHanded;
}
}
public ArrayList PositionsPlayed
{
get
{
return _positionsPlayed;
}
}
public int Hits
{
get
{
return _hits;
}
}
public int AtBats
{
get
{
return _atBats;
}
}
public double BattingAverage
{
get
{
return Math.Round((double)(_atBats / _hits), 3);
}
}
public int Doubles
{
get
{
return _doubles;
}
}
public int Triples
{
get
{
return _triples;
}
}
public int Homeruns
{
get
{
return _homeruns;
}
}
public int Walks
{
get
{
return _walks;
}
}
public int Strikeouts
{
get
{
return _strikeouts;
}
}
public double SluggingPercentage
{
get
{
int totalBases;
totalBases = (_hits - _doubles - _triples - _homeruns) + (_doubles * 2) + (_triples * 3) + (_homeruns * 4);
return Math.Round((double)(totalBases / _atBats), 3);
}
}
public int CaughtStealing
{
get
{
return _caughtStealing;
}
}
public int StolenBases
{
get
{
return _stolenBases;
}
}
public int StealingAttempts
{
get
{
return (_stolenBases + _caughtStealing);
}
}
}
}
|
In .NET you would access this player by doing something like...
| player BarryBonds = new player(); |
I could easily add in the constructor logic to pull stats out of a database or XML and populate this player with stats so that when he was constructed, he'd have values in those fields. But you should get the idea...
Now you can access all Barry's stats by using the properties like:
or | BarryBonds.SluggingPercentage |
We can now take this player and make a 9 item array of players and we now have a team.
Note that I calculated the batting average, slugging percentage and steal attmepts within the object and that the positions property is an ArrayList. If you're not familiar with what an array list is it's just a dynamically sized array.
Can something like this class be replicated in ColdFusion? If so can you show me the code to do it?
If we want to make this a REAL side by side comparison, I could come up with an Access DB or an XML file with some stats in it and we can both use the same data to actually make it work. |