RE: Test object type

2006-05-08 Thread Jim
listlast(getMetadata(obj).name,.)

probably more efficient to have a getType() function in each cfc though.
then perhaps a user.equals(anotherobj) function which utilises it e.g.

return if(arguments.obj.getType() eq this.getType())



-Original Message-
From: Joelle Tegwen [mailto:[EMAIL PROTECTED]
Sent: 08 May 2006 17:38
To: CF-Talk
Subject: Test object type


I have a User.cfc, Manager.cfc and Worker.cfc. Manager and Worker extend
User.

I would like to be able to test whether an instantiated object is a
Worker or a Manager.

Something like cfif isObjectType(#session.currentUser#,
#ttComponents.Manager#)

But I don't know what isObjectType is really called :)

Can I do this or do I need isWorker and isManager functions in my classes?

Thanks
Joelle



~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:239819
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: Test object type

2006-05-08 Thread Ben Nadel
As far as I know, CF doesn't have a built in instanceOf operator or
method. The way to get around this might be to have a public property for
objects Ex.:

SESSION.CurrentUser.InstanceOf()

Which would return, as a string, something like manager or worker.

...
Ben Nadel 
www.bennadel.com
-Original Message-
From: Joelle Tegwen [mailto:[EMAIL PROTECTED] 
Sent: Monday, May 08, 2006 12:38 PM
To: CF-Talk
Subject: Test object type

I have a User.cfc, Manager.cfc and Worker.cfc. Manager and Worker extend
User.

I would like to be able to test whether an instantiated object is a Worker
or a Manager.

Something like cfif isObjectType(#session.currentUser#,
#ttComponents.Manager#)

But I don't know what isObjectType is really called :)

Can I do this or do I need isWorker and isManager functions in my classes?

Thanks
Joelle



~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:239820
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: Test object type

2006-05-08 Thread Brad Wood
So I assume that you use session.currentUser to hold EITHER a manager
object OR a worker object.  

This may be a stupid question since I don't have a lot of oop
experience, but is it bad form to use the same variable name to store
two different types of objects?  That seems so create the problem you
have now, because you don't know what class you used to instantiate that
object.

~Brad

-Original Message-
From: Joelle Tegwen [mailto:[EMAIL PROTECTED] 
Sent: Monday, May 08, 2006 11:38 AM
To: CF-Talk
Subject: Test object type

I have a User.cfc, Manager.cfc and Worker.cfc. Manager and Worker extend

User.

I would like to be able to test whether an instantiated object is a 
Worker or a Manager.



~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:239823
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: Test object type

2006-05-08 Thread Dave Watts
 So I assume that you use session.currentUser to hold EITHER a 
 manager object OR a worker object.  
 
 This may be a stupid question since I don't have a lot of oop 
 experience, but is it bad form to use the same variable name 
 to store two different types of objects?  That seems so 
 create the problem you have now, because you don't know what 
 class you used to instantiate that object.

Actually, being able to use one variable to store different objects can be
very useful, and is commonly done in OO languages. However, these tend not
to be just any two different objects, but objects that either inherit from
the same base class or implement the same interface. For example, you might
have a bunch of objects that are sortable. You might write a single
interface, ISortable, then write functionality in each class to implement
how ISortable works for that specific object type. Then, if you have an
array of objects, all of which implement ISortable, you could sort them
without worrying about what kind of objects they are exactly.

This is a big deal in C# now, with the addition of generics - type-safe
collections of various kinds.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!


~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:239830
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: Test object type

2006-05-08 Thread Brad Wood
Ok, that makes sense.  So is there an instanceof method in CF or
something similar to tell you what class was used to create your object.

Also, can you create an interface with CFC's, and then implement that
interface with another class?  (Like other OOP languages)

~Brad

-Original Message-
From: Dave Watts [mailto:[EMAIL PROTECTED] 
Sent: Monday, May 08, 2006 12:22 PM
To: CF-Talk
Subject: RE: Test object type

 So I assume that you use session.currentUser to hold EITHER a 
 manager object OR a worker object.  
 
 This may be a stupid question since I don't have a lot of oop 
 experience, but is it bad form to use the same variable name 
 to store two different types of objects?  That seems so 
 create the problem you have now, because you don't know what 
 class you used to instantiate that object.

Actually, being able to use one variable to store different objects can
be
very useful, and is commonly done in OO languages. However, these tend
not
to be just any two different objects, but objects that either inherit
from
the same base class or implement the same interface. For example, you
might
have a bunch of objects that are sortable. You might write a single
interface, ISortable, then write functionality in each class to
implement
how ISortable works for that specific object type. Then, if you have an
array of objects, all of which implement ISortable, you could sort them
without worrying about what kind of objects they are exactly.

This is a big deal in C# now, with the addition of generics - type-safe
collections of various kinds. 


~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:239838
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: Test object type

2006-05-08 Thread Ian Skinner
Also, can you create an interface with CFC's, and then implement that interface 
with another class?  (Like other OOP languages)

~Brad

No not directly.  See the writings of Hal Helms and others on why this is not 
so good for CF.


--
Ian Skinner
Web Programmer
BloodSource
www.BloodSource.org
Sacramento, CA

-
| 1 |   |
-  Binary Soduko
|   |   |
-
 
C code. C code run. Run code run. Please!
- Cynthia Dunning

Confidentiality Notice:  This message including any
attachments is for the sole use of the intended
recipient(s) and may contain confidential and privileged
information. Any unauthorized review, use, disclosure or
distribution is prohibited. If you are not the
intended recipient, please contact the sender and
delete any copies of this message. 




~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:239840
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: Test object type

2006-05-08 Thread Dave Watts
 Ok, that makes sense. So is there an instanceof method in CF 
 or something similar to tell you what class was used to 
 create your object.

You can use GetMetaData() to find this out.

 Also, can you create an interface with CFC's, and then 
 implement that interface with another class? (Like other OOP 
 languages)

No, CF doesn't support interfaces. It does support inheritance, however,
which can involve the same issues.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!


~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:239848
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: Test object type

2006-05-08 Thread Phillip Holmes
[For some reason my original post didn't go through (I think because I
digitally sign my email). It had a typo anyway, so apologies if the original
finally comes through to the list.]

Exactly Right Dave.

Joelle,

In your base class, add something like this:

cfproperty name=userType type=string
cfparam name=this.userType default=worker type=string

You can set the this.userType upon instantiation and it will know what type
it is for the life of the object.

Then you can also put in something like this in your base class to search
your object hierachy 
for it's userType or whatever else you'd like to find down the line.

cffunction name=getInstance returntype=struct access=public
cfargument name=search type=string required=no default=
cfscript
var stObj = structNew();
if(len(trim(arguments.search)) GT 0) {
for(it in this) {
if(arguments.search IS it) {
stObj[it] = this[it];
return stObj ;
}
}
} else {
for(it in this){
stObj[it] = this[it];
}
}
return stObj;
/cfscript
/cffunction 


Warmest Regards,
 
Phillip B. Holmes
http://phillipholmes.com

===




-Original Message-
From: Dave Watts [mailto:[EMAIL PROTECTED] 
Sent: Monday, May 08, 2006 12:22 PM
To: CF-Talk
Subject: RE: Test object type

 So I assume that you use session.currentUser to hold EITHER a manager 
 object OR a worker object.
 
 This may be a stupid question since I don't have a lot of oop 
 experience, but is it bad form to use the same variable name to store 
 two different types of objects?  That seems so create the problem you 
 have now, because you don't know what class you used to instantiate 
 that object.

Actually, being able to use one variable to store different objects can be
very useful, and is commonly done in OO languages. However, these tend not
to be just any two different objects, but objects that either inherit from
the same base class or implement the same interface. For example, you might
have a bunch of objects that are sortable. You might write a single
interface, ISortable, then write functionality in each class to implement
how ISortable works for that specific object type. Then, if you have an
array of objects, all of which implement ISortable, you could sort them
without worrying about what kind of objects they are exactly.

This is a big deal in C# now, with the addition of generics - type-safe
collections of various kinds.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized instruction
at our training centers in Washington DC, Atlanta, Chicago, Baltimore,
Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!




~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:239877
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54