> -----Original Message----- > From: [email protected] > [mailto:[EMAIL PROTECTED] On Behalf Of Judah McAuley > Sent: Thursday, 13 November 2008 2:55 PM > To: [email protected] > Subject: [CFCDEV] Re: Is inheritance the right choice here? > > > > It sounds like you are suggesting though is that > getAbstractContact(103) would return a different looking > object depending on if that particular contact was of type > phone or email, correct? > > Thanks, > Judah > >
Yes. Nothing really wrong with the other approach, it amounts to about the same thing in terms of the data. Where the two approaches diverge is when you start adding behaviour. Think of an operation that in principle applies to any contact, but the details will differ depending on the method - say you want to send a reminder to the user. In the first approach, contact.sendReminder() would contain a case statement - if method is "email", email a reminder, if "phone" send a pre-recorded message, maybe send an SMS etc. In the second approach, sendReminder() would simply be implemented differently in each subclass. No ifs or case statements. It means that AbstractContact actually doesn't need to know what the methods are. This is called the "replace conditional with inheritance" pattern. Jaime --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
