Re: Multiple class inheritance
| From: | Sam Barrow | Date: | Mon, 19 Nov 2007 06:14:32 +0000 |
| Subject: | Re: Multiple class inheritance | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-33285@lists.php.net to get a copy of this message | ||
I was considering something like this, just seems like more of a hack to
me than the right way to do it, plus the performance hit you mentioned.
On Mon, 2007-11-19 at 00:11 -0600, Larry Garfield wrote:
> (Sorry, hit reply too soon.)
>
> Or, alternatively, you can mostly implement "friend" functions of a sort:
>
> http://www.garfieldtech.com/blog/php-magic-call
>
> but they have a performance penalty:
>
> http://www.garfieldtech.com/blog/magic-benchmarks
>
> On Sunday 18 November 2007, Sam Barrow wrote:
> > What is the general opinion on multiple class inheritance. I have a need
> > for it. I have objects for all user input fields.
> >
> > $username = new field ;
> > $username -> name = 'username' ;
> > $username -> maxLen = 32 ;
> >
> > I have three types of fields. Fields that are automatically put in the
> > database, such as timestamps, fields that are inputted but not stored,
> > such as "confirm password", and fields that are inputted by the user AND
> > stored in the database, such as username and password.
> >
> > Now i have 3 classes:
> >
> > - abstractField (has methods and properties that apply to all fields).
> > - inputField, extends abstractField (has methods and properties for
> > display of input form elements and labels).
> > - dbField, extends abstractField (has methods for storing and retrieving
> > in db, etc.).
> >
> > However for fields that are inputted AND stored in the db, i need to
> > extend both inputField and dbField.
> >
> > - inputDbField extends inputField, dbField.
> >
> > Sure, there may be quick hacks to do this, but the only proper way seems
> > to be to extend both classes, and I don't want to duplicate any code
> > (dbField and inputField are both pretty big, and any modifications will
> > also have to be replicated).
> >
> > And no, I don't want to use interfaces. Interfaces will barely do
> > anything for me, I'll still have to duplicate my method bodies, and
> > properties.
>
>
> --
> Larry Garfield AIM: LOLG42
> larry@garfieldtech.com ICQ: 6817012
>
> "If nature has made any one thing less susceptible than all others of
> exclusive property, it is the action of the thinking power called an idea,
> which an individual may exclusively possess as long as he keeps it to
> himself; but the moment it is divulged, it forces itself into the possession
> of every one, and the receiver cannot dispossess himself of it." -- Thomas
> Jefferson
>