I would be interested to see what those more experienced at OO than me would say about this, but I will tell you my approach.
(1) For the DataMgr, I have a getDatabase() method that returns the name of the database being used ("SQL Server", for example). I think that a getEmployeeType() would be similarly useful.
(2) On the flip side, if the task is something that seems like something that the employee is "doing", I might add a method to the employee - like "persist". Then you could take advantage of polymorphism and have the "persist" method do nothing except for programmers. Note that you would do this by over-riding the method, not by adding a conditional.
For (1), you could check the results of getEmployeeType() and then take an action.
For (2), you could just call persist() on each object, knowing that the method would only actually do anything for programmers.
Does that make sense? Am I off my rocker?
Thanks!
Steve
At 11:25 AM 12/7/2005, Dave Shuck wrote:
Thanks Steve. From my still very green and limited knowledge of OO, that is an example of polymorphism if I am not mistaken, correct? That being methods in sub-class objects overriding methods in the objects that they extend.> wrote:
I am fairly comfortable with that concept and created a mini-app yesterday based on Hal's example of employees each having different work() methods for their position that overrode the employee object work() method. Here is where I get kind of hung up is this...
Say I have the following code, and say that each of the objects I am instantiating below extends "employee", and within each object there is only a work() method that represents the work that is done by that position. The rest of the properties and methods are inherited from "employee" object.
<cfscript>
aEmployees = arraynew(1);
dave = createObject("component","cfc.programmer").init();
dave.setemployeeID(createUUID());
dave.setFirstName("Dave");
dave.setLastName ("Shuck");
dave.setHireDate("3/2/2004");
aEmployees[1] = dave;
jane = createObject("component","cfc.projectManager").init();
jane.setemployeeID(createUUID());
jane.setFirstName ("Jane");
jane.setLastName("Doe");
jane.setHireDate("2/15/2000");
aEmployees[2] = jane;
bob = createObject("component","cfc.marketingPerson").init();
bob.setemployeeID (createUUID());
bob.setFirstName("Bob");
bob.setLastName("Marketer");
bob.setHireDate("10/15/1999");
aEmployees[3] = bob;
</cfscript>
If I wanted to loop through that array and only do something [example: persist the data] to employees that were type "programmer", how would that best be accomplished in code?
~Dave
On 12/7/05, Steve Bryant < [EMAIL PROTECTED]
- Here is my best example (if my example is wrong, please somebody let
me know):
- DataMgr
- DataMgr_Access is a DataMgr (for MS Access)
- DataMgr_MSSQL is a DataMgr (for MS SQL Server)
- DataMgr_MySQL is a DataMgr (for MySQL)
- DataMgr_PostGreSQL is a DataMgr (for PostGreSQL)
- Each of these inherits behavior from the parent object, but extends
- that behavior for the specifics of that database.
- http://www.bryantwebconsulting.com/cfcs/
- Hope that helps!
- Steve Bryant.
- Bryant Web Consulting LLC
- http://www.BryantWebConsulting.com/
- http://steve.coldfusionjournal.com/
- At 10:28 AM 12/7/2005, Dave Shuck wrote:
- >One of the concepts that I read about, and I understand from the
- >thousand foot view is making use of "types" of objects, but I am
- >having a hard time with translating that to what it means in
- >code. In the example, of the AJ Foyt Car Center (or something like
- >that), they would only accept vehicles of type "sportsCar", given
- >that sportsCar extends "car" and car extends "vehicle". Does anyone
- >have a code example of something like that? I realize that once I
- >see it it will likely seem glaringly obvious, but for some reason I
- >am just having a hard time visualizing that code in a real implementation.
- >
- >Thanks,
- >
- >--
- >~Dave Shuck
- >< mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]
- > www.daveshuck.com
- DataMgr
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).
An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
