[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Picking the Tools -- Marrying processing models to data models

  • From: Uche Ogbuji <uche.ogbuji@f...>
  • To: "Al B. Snell" <alaric@a...>
  • Date: Wed, 23 May 2001 09:34:41 -0600 (MDT)

smtpemailer
> > My point is that you can get all the benefits of swapping in the Customer
> > code without late binding tied exclusively to inheritance.  IOW,
> > polymorphism is much bigger than OO.
>
> Gimmee an example, I don't totally follow you...

Here's somthing in Python, a language, remember, that is basically OO but
gives you plenty of escape hatches from OO when you need them.


old classes:

class UUCPEmailer:
    def sendMessage(self, email, msg):
        #do your UUCP magic here
        pass


class Customer:
    #Basically a static class variable
    emailMixin = UUCPEmailer()

    #Basically a constructor
    def __init__(self, name, email):
        self._name = name
        self._email = email
        return

    def sendBulletin(self, msg):
        self.emailMixin.sendMessage(self.email, msg)

So now we've changed our entire systems and we use SMTP for e-mail rather
than UUCP.  Never fear, there are myriad ways to re-use our customer code.
One is

class SMTPEmailer:
    def sendMessage(self, email, msg):
        #do your SMTP magic here
        pass

Customer.emailMixin = SMTPEmailer()

And that's it.  We changed a core aspect of the system without needing to
scrap the customer code.  No OO involved, just techniques familiar to
any library.  We implemnented late binding through metaprogramming rather
than inheritance polymorphism.  This sort of thing is a snap, and I do it
quite often without needing inheritance or limited polymorphism, because
my language of choice allows me to.

In my example I mixed-in functionality through association.  I could have
done it with inheritance as well, using Inheritance-based Mixins:

class UUCPEmailerMixin:
    #The underscore sort of makes it a private method
    def _sendMessage(self, email, msg):
        #do your UUCP magic here
        pass


#Inherit from UUCPEmailerMixin
class Customer(UUCPEmailerMixin):

    #Basically a constructor
    def __init__(self, name, email):
        self._name = name
        self._email = email
        return

    def sendBulletin(self, msg):
        self.emailMixin._sendMessage(self.email, msg)

After the migration to SMTP:

class SMTPmailerMixin:
    #The underscore sort of makes it a private method
    def _sendMessage(self, email, msg):
        #do your SMTP magic here
        pass

#Note the order of inheritance, due to Python look-up rules
class NewCustomer(SMTPmailerMixin, Customer)
    #That's *all* that is required of the new class body
    pass


I could also have done this with delegation or even the most primitive
method of polymorphism: dynamically swapping in a new sendMessage method
body for Customer at run-time.

All very simple, really.  No great insights I offer.  Just a reminder that
all of this is soup without One Methodology to Rule Them All.


-- 
Uche Ogbuji                               Principal Consultant
uche.ogbuji@f...               +1 303 583 9900 x 101
Fourthought, Inc.                         http://Fourthought.com
4735 East Walnut St, Ste. C, Boulder, CO 80301-2537, USA
Software-engineering, knowledge-management, XML, CORBA, Linux, Python



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.