My Kingdom for Multiple Inheritance

I’ve mostly been working in Visual FoxPro the past few weeks, sorting through the odds and ends of different projects to glean the best of the class libraries I’ve developed over the years. It’s an exciting time for me, because I have two projects starting from scratch, and both will use VFP 9.0. (I know. My life is unbelievably boring, but I like it that way.)

Most of my work has involved taking on legacy projects in unrelated business domains. These systems weren’t developed so much as accreted. I enjoy the challenge of extending and imposing at least some design on an existing system. Some of the projects have had parts in different versions of Fox from FoxPro to VFP, most have involved more than one developer, and none have used a commercial framework. (This explains my giddy delight upon discovering refactoring.) Interesting work, but it just plain hurts my brain to go from FoxPro 2.x to C# in a single day, or even a week, especially when the domains are different, too.

Therefore, I’m thrilled to have two brand spanking new projects. Over the years, I’ve developed some useful class libraries that I’d like to use in on these projects. The trouble is, the usefulness is scatter between 1/2 a dozen projects. So, it’s been a hair pulling exercise to recall where different features live and how best to integrate them into one place. Refactoring isn’t appropriate in this situation, although I did, at first, misuse it, by mixing it up with new development.

What’s all this got to do with multiple inheritance? I’d love to be able to create native interfaces in VFP. As marvelous as it is, there is no elegant way for several classes to inherit a common set of methods and properties. Worse, there is no clean way for code to know if an object implements some functionality. There are ways around the problem, but any solution is painful to some degree and requires cut-and-paste coding and reliance on an internal system convention–blech.

I try to follow the idea from Agile programming of coding what’s needed now, but coding flexibly for what may be needed later (my interpretation). That’s how I have useful functionality scattered throughout several projects. *sigh*

Thankfully, VFP has only a handful of native classes so systematically adding a common set of methods and properties to classes is relatively quick. So, back to ditch digging …perhaps soon I’ll be able to move on to building the lovely palace.

Advertisements

4 thoughts on “My Kingdom for Multiple Inheritance

  1. Holy crap, Batman! My brain’s going to explode! Thanks, Arnon, for yet-another-cool-concept. Yes, I think I might like mixins. I still would like to be able to code native interfaces, though. It’s useful to be able to manipulate an object’s interface as an object itself.

  2. Nancy: you can build a “Defaults” class, add it as a property of your main class,
    and use it directly or vía This_Access:


    CLEAR

    WITH NEWOBJECT("xClass")
    ? .MyProp1
    ? .Defaults.MyPropD1 && Direct reference
    ? .MyPropD1 && Reference vía This_Access
    .MyMethodD1()
    ENDWITH

    RETURN

    DEFINE CLASS xClass AS Custom
    Defaults = NULL
    MyProp1 = 1

    PROCEDURE Init
    This.Defaults = NEWOBJECT("xDefaults")
    ENDPROC

    PROCEDURE This_Access (sProp)

    IF PEMSTATUS(This, sProp, 5)
    RETURN This
    ELSE
    RETURN This.Defaults
    ENDIF
    ENDPROC
    ENDDEFINE

    DEFINE CLASS xDefaults AS Custom
    MyPropD1 = 1
    MyPropD2 = 2
    MyPropD3 = 3

    PROCEDURE MyMethodD1
    WAIT WINDOW PROGRAM()
    ENDPROC
    ENDDEFINE

    Looks “elegant” to me, at least.

    Best wishes & sorry for my english
    Pablo

  3. Hi, Pablo-

    Thanks for your comment. As always both your code and your English is excellent! I agree there are ways to program around the lack of native interfaces. I have long done so, in fact, for error handling, associating business logic with user interface objects, and so on. I don’t mean to insult the way anyone has programmed solutions by describing it as inelegant. It is elegant for VFP, but not, IMHO, in the context of other solutions in other languages. VFP is great, but it’s not perfect. :-)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s