I wouldn't do it this way, simply because I couldn't ask a phone
contact for its email address, and visa versa. It also seems a little
contrived that the either of the contact types don't know what their
type is until another entity (the database, in this case) makes an
informed choice. Contact type seems more of a property of a Contact.
Why create that barrier?
Not knowing more about the context of your application, you may be
better off modeling the real world. If you ask a phone contact over
the phone for their email address, they know it. If you ask a contact
when they walk in the door if they phoned or emailed their order in,
they can tell you.
You could take the same approach with any number of properties,
creating separate objects for MaleContacts and FemaleContacts for
instance, or what about AdultContacts and ChildContacts? Now what do
we do about a FemaieAdultPhoneContact?
Sorry for belaboring the point. It's late at night here in Switzerland ;-)
Nando
On Thu, Nov 13, 2008 at 1:50 AM, Jaime Metcher
<[EMAIL PROTECTED]> wrote:
>
> Hi Judah,
>
> That sounds about right. So you'd have something like:
>
> getContactByID(id):
> // whatever arrangement you have for grabbing the right record out
> of the database
> query = select from Contact left join PhoneContact left join
> EmailContact where ContactID = :id
>
> if (query.contactType is "phone")
> return CreateObject("PhoneContact").init(query.Field1,...)
> else if (query.contactType is "email")
> return CreateObject("EmailContact").init(query.Field1,...)
>
> The PhoneContact and EmailContact objects would be inheriting some of those
> fields from Contact. The main point is that you ask for a Contact, but what
> you actually get back is on of the subtypes.
>
> Jaime
>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[EMAIL PROTECTED] On Behalf Of Judah McAuley
>> Sent: Thursday, 13 November 2008 8:45 AM
>> To: [email protected]
>> Subject: [CFCDEV] Is inheritance the right choice here?
>>
>>
>> I'm trying to sort out the best way to model a scenario. The
>> basic setup is this:
>>
>> I've got a queue of contacts that will be going out. Each
>> Contact has some common information about it like an id, the
>> customer it is associated with, and a method.
>>
>> The method can be either a phone contact or an email contact.
>> Depending on which type it is, I need to have further
>> (different) information. So a phone contact will need to have
>> the phone number its going to along with some miscellaneous
>> info. If it is an email contact, it needs an email address it
>> is going to, the subject, body, etc.
>>
>> So how best to implement this with cfc's? Should I have one
>> cfc for the Contact class with getters and setters for the
>> information that is common to all contacts and then have to
>> other cfc's that extend the base Contact, one for email
>> contacts and one for phone contacts? I think that is the
>> correct way to do it, but I'm second guessing myself.
>>
>> And if that is the correct way, what is the preferred way to
>> get a contact as a whole? My assumption is that in my getter
>> for the Contact object, I'd pass in an id for the Contact,
>> then within the getter I'd check the contact method and
>> either run the emailContact getter or the phoneContact getter
>> to fetch the object representing the method-specific info.
>> Does that sound right?
>>
>> Thanks in advance,
>> Judah
>>
>> >
>>
>
>
>
> >
>
--
Nando M. Breiter
The CarbonZero Project
CP 234
6934 Bioggio
Switzerland
+41 76 303 4477
[EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CFCDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---